本文整理汇总了PHP中lithium\util\String类的典型用法代码示例。如果您正苦于以下问题:PHP String类的具体用法?PHP String怎么用?PHP String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了String类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _save
/**
* Save a template with the current params. Writes file to `Create::$path`.
* Override default save to add timestamp in file name.
*
* @param array $params
* @return string A result string on success of writing the file. If any errors occur along
* the way such as missing information boolean false is returned.
*/
protected function _save(array $params = array())
{
$defaults = array('namespace' => null, 'class' => null);
$params += $defaults;
if (empty($params['class']) || empty($this->_library['path'])) {
return false;
}
$contents = $this->_template();
$result = String::insert($contents, $params);
$namespace = str_replace($this->_library['prefix'], '\\', $params['namespace']);
$date = date('YmdHis');
$path = str_replace('\\', '/', "{$namespace}\\{$date}_{$params['class']}");
$path = $this->_library['path'] . stristr($path, '/');
$file = str_replace('//', '/', "{$path}.php");
$directory = dirname($file);
$relative = str_replace($this->_library['path'] . '/', "", $file);
if (!is_dir($directory) && !mkdir($directory, 0755, true)) {
return false;
}
if (file_exists($file)) {
$prompt = "{$relative} already exists. Overwrite?";
$choices = array('y', 'n');
if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['class']} skipped.";
}
}
if (file_put_contents($file, "<?php\n\n{$result}\n\n?>")) {
return "{$params['class']} created in {$relative}.";
}
return false;
}
开发者ID:djordje,项目名称:li3_migrations,代码行数:39,代码来源:Migration.php
示例2: generate
/**
* Generate hashed and salted token from `'prefix'` and `md5` hashed `$email` value
* @param $email string User email that will be used as base for secret token
* @param array $options Supported options:
* - `'prefix'` _string|int_ If not passed this method will generate random int from
* `100000` to `999999`. Hashed email will be prefixed with value of this option.
* Example: `'prefix_value' . md5($email)`
* - All other options are same as `lithium\util\String::hash()`
* @return string Hashed prefixed email salted and hashed again
* @see lithium\util\String::hash()
*/
public static function generate($email, array $options = array())
{
$options += array('prefix' => null, 'salt' => LI3_UM_TokenSalt, 'type' => 'sha256');
$prefix = $options['prefix'] ? $options['prefix'] : mt_rand(100000, 999999);
unset($options['prefix']);
return String::hash($prefix . md5($email), $options);
}
开发者ID:djordje,项目名称:li3_usermanager,代码行数:18,代码来源:Token.php
示例3: _save
/**
* Override the save method to handle view specific params.
*
* @param array $params
* @return mixed
*/
protected function _save(array $params = array())
{
$params['path'] = Inflector::underscore($this->request->action);
$params['file'] = $this->request->args(0);
$contents = $this->_template();
$result = String::insert($contents, $params);
if (!empty($this->_library['path'])) {
$path = $this->_library['path'] . "/views/{$params['path']}/{$params['file']}";
$file = str_replace('//', '/', "{$path}.php");
$directory = dirname($file);
if (!is_dir($directory)) {
if (!mkdir($directory, 0755, true)) {
return false;
}
}
$directory = str_replace($this->_library['path'] . '/', '', $directory);
if (file_exists($file)) {
$prompt = "{$file} already exists. Overwrite?";
$choices = array('y', 'n');
if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['file']} skipped.";
}
}
if (is_int(file_put_contents($file, $result))) {
return "{$params['file']}.php created in {$directory}.";
}
}
return false;
}
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:35,代码来源:View.php
示例4: key
/**
* Obtain the session key.
*
* For this adapter, it is a UUID based on the SERVER_ADDR variable.
*
* @return string UUID.
*/
public static function key()
{
$context = function ($value) use(&$config) {
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
};
return String::uuid($context);
}
开发者ID:EHER,项目名称:monopolis,代码行数:14,代码来源:Memory.php
示例5: addModules
public static function addModules($modules)
{
$modules = (array) $modules;
$calledClass = get_called_class();
$baseClassName = array_pop(explode('\\', $calledClass));
if (!isset(self::$_modules[$calledClass])) {
self::$_modules[$calledClass] = array();
}
foreach ($modules as $name => $config) {
if (is_integer($name) and is_string($config)) {
$name = $config;
$config = array();
}
$current = isset(self::$_modules[$calledClass][$name]) ? self::$_modules[$calledClass][$name] : ($current = array());
$defaults = array('class' => String::insert('\\app\\modules\\{:class}\\{:name}Module', array('class' => $baseClassName, 'name' => ucfirst($name))), 'partial' => String::insert('modules/{:class}/{:name}', array('class' => $baseClassName, 'name' => $name)));
self::$_modules[$calledClass][$name] = $config + $defaults + $current;
if (!class_exists(self::$_modules[$calledClass][$name]['class'])) {
throw new \Exception('Module class ' . self::$_modules[$calledClass][$name]['class'] . ' not found.');
}
if (isset($config['filters'])) {
foreach ($config['filters'] as $function => $filter) {
static::applyFilter($function, $filter);
}
}
}
return true;
}
开发者ID:aniston,项目名称:Platypus,代码行数:27,代码来源:Model.php
示例6: process
/**
* Process incoming messages
*
* @param string $data
* @return string
*/
public function process($data)
{
$responses = $this->_responses;
$model = $this->_classes['model'];
$location = null;
extract($data);
$words = preg_split("/[\\s]/", $message, 2);
if ($words[0] != '~weather') {
return;
}
if (!isset($words[1])) {
return String::insert($responses['missing'], compact('user'));
}
$location = $model::find('search', $words[1]);
if (!$location || isset($location->title)) {
return String::insert($responses['unknown'], compact('user') + array('location' => $words[1]));
}
if (isset($location->location)) {
$location = $model::find('search', $location->location[0]->name);
if (!$location || isset($location->title)) {
return String::insert($responses['unknown'], compact('user') + array('location' => $words[1]));
}
}
$station = $location->nearby_weather_stations->airport->station[0];
$weather = $model::find('station', (string) $station->icao);
if (!$weather || isset($weather->title)) {
return String::insert($responses['unknown'], compact('user') + array('location', $words[1]));
}
return String::insert($responses['weather'], compact('user') + array('city' => (string) $station->city, 'state' => (string) $station->state, 'country' => (string) $station->country, 'icao' => (string) $station->icao, 'temperature' => (string) $weather->temperature_string, 'windchill' => (string) $weather->windchill_string, 'wind' => (string) $weather->wind_string));
}
开发者ID:unionofrad,项目名称:li3_bot,代码行数:36,代码来源:Weather.php
示例7: apply
/**
* With lots of various rules we created 4 various rulesets for operators. If one
* of the tokens or content is found we use the given regex on the joined array.
*
* @param Testable $testable The testable object
* @return void
*/
public function apply($testable, array $config = array())
{
$tokens = $testable->tokens();
foreach ($this->inspector as $inspector) {
if (isset($inspector['tokens'])) {
$byToken = $testable->findAll($inspector['tokens']);
} else {
$byToken = array();
}
if (isset($inspector['content'])) {
$byContent = $testable->findAllContent($inspector['content']);
} else {
$byContent = array();
}
foreach (array_merge($byToken, $byContent) as $id) {
$token = $tokens[$id];
$isPHP = $testable->isPHP($token['line']);
if ($isPHP && empty($token['isString'])) {
$pattern = String::insert($inspector['regex'], array('content' => preg_quote($token['content'], "/")));
$firstId = $id - $inspector['relativeTokens']['before'];
$firstId = $firstId < 0 ? 0 : $firstId;
$length = $inspector['relativeTokens']['length'];
$inspectTokens = array_slice($tokens, $firstId, $length);
$html = null;
foreach ($inspectTokens as $htmlToken) {
$html .= $htmlToken['content'];
}
if (preg_match($pattern, $html) === 0) {
$this->addViolation(array('message' => String::insert($inspector['message'], $token), 'line' => $token['line']));
}
}
}
}
}
开发者ID:unionofrad,项目名称:li3_quality,代码行数:41,代码来源:OperatorSpacing.php
示例8: process
/**
* Process incoming messages.
*
* @param string $data
* @return string
*/
public function process($data)
{
$model = $this->_classes['model'];
extract($data);
if ($message[0] != '~') {
return;
}
list($command, $recipient) = preg_split("/[\\s]/", $message, 2) + array(null, null);
if (!($recipient = trim($recipient))) {
return;
}
if ($command == '~inc') {
if ($recipient == $user) {
return String::insert($this->_responses['self'], compact('user'));
}
$model::increment($recipient);
$current = $model::current($recipient);
return String::insert($this->_responses['update'], compact('recipient', 'current'));
} elseif ($command == '~dec') {
if ($model::current($recipient) == 0) {
return String::insert($this->_responses['decrementFail'], compact('recipient'));
}
$model::decrement($recipient);
$current = $model::current($recipient);
return String::insert($this->_responses['update'], compact('recipient', 'current'));
} elseif ($command == '~karma') {
$current = $model::current($recipient);
return String::insert($this->_responses['current'], compact('recipient', 'current'));
}
}
开发者ID:unionofrad,项目名称:li3_bot,代码行数:36,代码来源:Karma.php
示例9: url
public function url($url, array $options = [])
{
$absolute = static::_url();
return function ($self, $params) use($url, $absolute, $options) {
$style = ['style' => $options['key']];
return $absolute . String::insert($url, $style);
};
}
开发者ID:johnny13,项目名称:li3_uploadable,代码行数:8,代码来源:Image.php
示例10: __construct
/**
* Constructor.
*
* @param array $config Configuration options.
*/
public function __construct(array $config = array())
{
$defaults = array('scheme' => 'https', 'host' => '{:login}.freshbooks.com', 'port' => null, 'login' => null, 'password' => '', 'auth' => 'Basic', 'version' => '1.1', 'path' => '/api/2.1');
$config += $defaults;
$config['host'] = String::insert($config['host'], $config);
$config['login'] = $config['password'];
$config['password'] = 'x';
parent::__construct($config);
}
开发者ID:radify,项目名称:li3_freshbooks,代码行数:14,代码来源:Freshbooks.php
示例11: interpolate
public function interpolate($file)
{
$styles = $this->_config['styles'];
$return = [];
foreach ($styles as $style => $dimension) {
$return[$dimension] = String::insert($file, ['style' => $style]);
}
return $return;
}
开发者ID:johnny13,项目名称:li3_uploadable,代码行数:9,代码来源:Imagine.php
示例12: _paths
protected function _paths($type, array $params)
{
if (!isset($this->_paths[$type])) {
throw new TemplateException("Invalid template type '{$type}'.");
}
return array_map(function ($path) use($params) {
return String::insert($path, $params);
}, (array) $this->_paths[$type]);
}
开发者ID:globus40000,项目名称:li3_mailer,代码行数:9,代码来源:FileLoader.php
示例13: _render
protected function _render($method, $string, $params, $options = array())
{
$defaults = array();
$options += $defaults;
foreach ($params as $key => $value) {
$params[$key] = $this->_context->applyHandler($this, $method, $key, $value, $options);
}
$strings = $this->_context ? $this->_context->strings() : $this->_strings;
return String::insert(isset($strings[$string]) ? $strings[$string] : $string, $params);
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:10,代码来源:Helper.php
示例14: __init
public static function __init()
{
parent::__init();
static::applyFilter('create', function ($self, $params, $chain) {
if (empty($params['data']['id'])) {
$params['data']['id'] = String::uuid();
}
return $chain->next($self, $params, $chain);
});
}
开发者ID:notomato,项目名称:li3_activitystreams,代码行数:10,代码来源:Base.php
示例15: apply
/**
* Will iterate over each line checking if any weak comparison operators
* are used within the code.
*
* @param Testable $testable The testable object
* @return void
*/
public function apply($testable, array $config = array())
{
$tokens = $testable->tokens();
$message = 'Weak comparison operator {:key} used, try {:value} instead';
$filtered = $testable->findAll(array_keys($this->inspectableTokens));
foreach ($filtered as $id) {
$token = $tokens[$id];
$this->addWarning(array('message' => String::insert($message, array('key' => token_name($token['id']), 'value' => $this->inspectableTokens[$token['id']])), 'line' => $token['line']));
}
}
开发者ID:unionofrad,项目名称:li3_quality,代码行数:17,代码来源:WeakComparisonOperators.php
示例16: render
/**
* Renders content from a template file provided by `template()`.
*
* @param string $template
* @param array $data
* @param array $options
* @return string
*/
public function render($template, $data = array(), $options = array())
{
$context = array();
$this->_context = $options['context'] + $this->_context;
foreach (array_keys($this->_context) as $key) {
$context[$key] = $this->__get($key);
}
$data = array_merge($this->_toString($context), $this->_toString($data));
return String::insert($template, $data, $options);
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:18,代码来源:Simple.php
示例17: write
/**
* Appends a message to a log file.
*
* @see lithium\analysis\Logger::$_priorities
* @param string $priority The message priority. See `Logger::$_priorities`.
* @param string $message The message to write to the log.
* @return \Closure Function returning boolean `true` on successful write, `false` otherwise.
*/
public function write($priority, $message)
{
$config = $this->_config;
return function ($self, $params) use(&$config) {
$path = $config['path'] . '/' . $config['file']($params, $config);
$params['timestamp'] = date($config['timestamp']);
$message = String::insert($config['format'], $params);
return file_put_contents($path, $message, FILE_APPEND);
};
}
开发者ID:fedeisas,项目名称:lithium,代码行数:18,代码来源:File.php
示例18: trace
/**
* Outputs a stack trace based on the supplied options.
*
* @param array $options Format for outputting stack trace. Available options are:
* - `'args'`: A boolean indicating if arguments should be included.
* - `'depth'`: The maximum depth of the trace.
* - `'format'`: Either `null`, `'points'` or `'array'`.
* - `'includeScope'`: A boolean indicating if items within scope
* should be included.
* - `'scope'`: Scope for items to include.
* - `'start'`: The depth to start with.
* - `'trace'`: A trace to use instead of generating one.
* @return string|array|null Stack trace formatted according to `'format'` option.
*/
public static function trace(array $options = array())
{
$defaults = array('depth' => 999, 'format' => null, 'args' => false, 'start' => 0, 'scope' => array(), 'trace' => array(), 'includeScope' => true, 'closures' => true);
$options += $defaults;
$backtrace = $options['trace'] ?: debug_backtrace();
$scope = $options['scope'];
$count = count($backtrace);
$back = array();
$traceDefault = array('line' => '??', 'file' => '[internal]', 'class' => null, 'function' => '[main]');
for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
$trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]);
$function = '[main]';
if (isset($backtrace[$i + 1])) {
$next = $backtrace[$i + 1] + $traceDefault;
$function = $next['function'];
if (!empty($next['class'])) {
$function = $next['class'] . '::' . $function . '(';
if ($options['args'] && isset($next['args'])) {
$args = array_map(array('static', 'export'), $next['args']);
$function .= join(', ', $args);
}
$function .= ')';
}
}
if ($options['closures'] && strpos($function, '{closure}') !== false) {
$function = static::_closureDef($backtrace[$i], $function);
}
if (in_array($function, array('call_user_func_array', 'trigger_error'))) {
continue;
}
$trace['functionRef'] = $function;
if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
$back[] = array('file' => $trace['file'], 'line' => $trace['line']);
} elseif (is_string($options['format']) && $options['format'] !== 'array') {
$back[] = String::insert($options['format'], array_map(function ($data) {
return is_object($data) ? get_class($data) : $data;
}, $trace));
} elseif (empty($options['format'])) {
$back[] = $function . ' - ' . $trace['file'] . ', line ' . $trace['line'];
} else {
$back[] = $trace;
}
if (!empty($scope) && array_intersect_assoc($scope, $trace) == $scope) {
if (!$options['includeScope']) {
$back = array_slice($back, 0, count($back) - 1);
}
break;
}
}
if ($options['format'] === 'array' || $options['format'] === 'points') {
return $back;
}
return join("\n", $back);
}
开发者ID:unionofrad,项目名称:lithium,代码行数:68,代码来源:Debugger.php
示例19: write
/**
* Writes the message to the configured cache adapter.
*
* @param string $type
* @param string $message
* @return closure Function returning boolean `true` on successful write, `false` otherwise.
*/
public function write($type, $message)
{
$config = $this->_config + $this->_classes;
return function ($self, $params) use($config) {
$params += array('timestamp' => strtotime('now'));
$key = $config['key'];
$key = is_callable($key) ? $key($params) : String::insert($key, $params);
$cache = $config['cache'];
return $cache::write($config['config'], $key, $params['message'], $config['expiry']);
};
}
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:18,代码来源:Cache.php
示例20: display
/**
* Main method
* @param array $menu The menu description.
* @param array $options Options.
* @return string The HTML buffer.
*/
public function display(array $menu, array $options = array())
{
$options += static::$defaults;
$menu = $this->_prepare($menu, $options);
$out = String::insert($options['open'], $options);
foreach ($menu as $item) {
$out .= String::insert($options['content'], $item);
}
$out .= $options['close'];
return $out;
}
开发者ID:scharrier,项目名称:li3_menu,代码行数:17,代码来源:Menu.php
注:本文中的lithium\util\String类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论