当前位置: 首页>>代码示例>>PHP>>正文


PHP util\String类代码示例

本文整理汇总了PHP中lithium\util\String的典型用法代码示例。如果您正苦于以下问题:PHP String类的具体用法?PHP String怎么用?PHP String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的lithium\util\String类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。