本文整理汇总了PHP中String::tokenize方法的典型用法代码示例。如果您正苦于以下问题:PHP String::tokenize方法的具体用法?PHP String::tokenize怎么用?PHP String::tokenize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::tokenize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPluginControllerName
public function getPluginControllerName($ctrlName = null)
{
$arr = String::tokenize($ctrlName, '/');
if (count($arr) == 2) {
return $arr[1];
} else {
return false;
}
}
示例2: folder
/**
* Main execution function to indent a folder recursivly
*
* @return int|null
*/
public function folder()
{
if (!empty($this->params['extensions'])) {
$this->settings['files'] = String::tokenize($this->params['extensions']);
}
if (!empty($this->params['again'])) {
$this->settings['againWithHalf'] = true;
}
if (!empty($this->args)) {
if (!empty($this->args[0]) && $this->args[0] !== 'app') {
$folder = $this->args[0];
if ($folder === '/') {
$folder = APP;
}
$folder = realpath($folder);
if (!file_exists($folder)) {
return $this->error('folder not exists: ' . $folder . '');
}
$this->_paths[] = $folder;
} elseif ($this->args[0] === 'app') {
$this->_paths[] = APP;
}
if (!empty($this->params['files'])) {
$this->settings['files'] = explode(',', $this->params['files']);
}
$this->out($folder);
$this->out('searching...');
$this->_searchFiles();
$this->out('found: ' . count($this->_files));
if (!empty($this->params['dry-run'])) {
$this->out('TEST DONE');
} else {
$continue = $this->in('Modifying files! Continue?', ['y', 'n'], 'n');
if (strtolower($continue) !== 'y' && strtolower($continue) !== 'yes') {
return $this->error('...aborted');
}
$this->_correctFiles();
$this->out('DONE');
}
} else {
$this->out('Usage: cake intend folder');
$this->out('"folder" is then intended recursivly');
$this->out('default file types are');
$this->out('[' . implode(', ', $this->settings['files']) . ']');
$this->out('');
$this->out('Specify file types manually:');
$this->out('-files php,js,css');
}
}
示例3: admin_index
/**
* Admin Index
*
* @access public
*/
function admin_index()
{
// Carrega Model
$this->loadModel($this->AclCaching->getAroModel());
// Seleciona todos os grupos de usuários
$roles = $this->{$this->AclCaching->getAroModel()}->find('all', array('order' => array(sprintf('%s.%s', $this->AclCaching->getAroModel(), $this->AclCaching->getAroDisplayField()) => 'ASC')));
// Seleciona todas as actions do sistema
$actions = $this->AclCaching->get_all_actions();
/**
* Carrega as permissões
*/
$permissions = array();
$methods = array();
foreach ($actions as $full_action) {
$url = String::tokenize($full_action, '/');
if (count($url) == 2) {
$plugin_name = null;
$controller_name = $url[0];
$action = $url[1];
} elseif (count($url) == 3) {
$plugin_name = $url[0];
$controller_name = $url[1];
$action = $url[2];
}
foreach ($roles as $role) {
$aro_node = $this->AclCaching->Aro->node($role);
if (!empty($aro_node)) {
$aco_node = $this->AclCaching->Aco->node($full_action);
if (!empty($aco_node)) {
$authorized = $this->AclCaching->checkDB($role, $full_action);
$permissions[$role[$this->AclCaching->getAroModel()][$this->AclCaching->getAroPrimaryKey()]] = $authorized ? 1 : 0;
}
} else {
/*
* Não conseguiu verificar a permissão
*/
$permissions[$role[$this->AclCaching->getAroModel()][$this->AclCaching->getAroPrimaryKey()]] = -1;
}
}
if (isset($plugin_name)) {
$methods['plugin'][$plugin_name][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
} else {
$methods['app'][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
}
}
// Envia variáveis para a View
$this->set(compact(array('roles', 'methods')));
}
示例4: extract
public static function extract(array $data, $path)
{
if (empty($path)) {
return $data;
}
// Simple paths.
if (!preg_match('/[{\\[]/', $path)) {
return (array) self::get($data, $path);
}
if (strpos($path, '[') === false) {
$tokens = explode('.', $path);
} else {
$tokens = String::tokenize($path, '.', '[', ']');
}
$_key = '__set_item__';
$context = array($_key => array($data));
foreach ($tokens as $token) {
$next = array();
$conditions = false;
$position = strpos($token, '[');
if ($position !== false) {
$conditions = substr($token, $position);
$token = substr($token, 0, $position);
}
foreach ($context[$_key] as $item) {
foreach ((array) $item as $k => $v) {
if (self::_matchToken($k, $token)) {
$next[] = $v;
}
}
}
// Filter for attributes.
if ($conditions) {
$filter = array();
foreach ($next as $item) {
if (is_array($item) && self::_matches($item, $conditions)) {
$filter[] = $item;
}
}
$next = $filter;
}
$context = array($_key => $next);
}
return $context[$_key];
}
示例5: acoslist
function acoslist()
{
$roles = $this->Role->find('all', array('order' => 'name', 'contain' => false, 'recursive' => -1));
$actions = $this->AclReflector->get_all_actions();
$permissions = array();
$methods = array();
foreach ($actions as $full_action) {
$arr = String::tokenize($full_action, '/');
if (count($arr) == 2) {
$plugin_name = null;
$controller_name = $arr[0];
$action = $arr[1];
} elseif (count($arr) == 3) {
$plugin_name = $arr[0];
$controller_name = $arr[1];
$action = $arr[2];
}
foreach ($roles as $role) {
$aro_node = $this->Acl->Aro->node($role);
if (!empty($aro_node)) {
$aco_node = $this->Acl->Aco->node($full_action);
if (!empty($aco_node)) {
$authorized = $this->Acl->check($role, $full_action);
$permissions[$role['Role']['id']] = $authorized ? 1 : 0;
}
} else {
/*
* No check could be done as the ARO is missing
*/
$permissions[$role['Role']['id']] = -1;
}
}
if (isset($plugin_name)) {
$methods['plugin'][$plugin_name][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
} else {
$methods['app'][$controller_name][] = array('name' => $action, 'permissions' => $permissions);
}
}
$this->set('roles', $roles);
$this->set('actions', $methods);
}
示例6: saveSection
function saveSection($data)
{
$this->set($data);
$success = false;
if ($success = $this->validates()) {
$tokens = String::tokenize($data[$this->name]['match_route']);
foreach ($tokens as $token) {
// There are three different cases
// 1- :param => value
// 2- pass => array('value1', 'value2')
// 3- named => array('param1' => 'value1', 'param2' => 'value2')
switch (true) {
// Case 1 - :param => value
case count($param = explode('=>', $token)) > 1:
$param = MenuItemRoute::cleanParam($param);
MenuItemRoute::getInstance()->route[$param['name']] = $param['value'];
break;
// Case 2 - named => array('param1' => 'value1', 'param2' => 'value2', ...)
// Case 2 - named => array('param1' => 'value1', 'param2' => 'value2', ...)
case count($param = explode(':', $token)) > 1:
$param = MenuItemRoute::cleanParam($param);
MenuItemRoute::getInstance()->route[] = $param['name'] . ':' . $param['value'];
break;
// Case 3 - pass => array('value1', 'value2', ...)
// Case 3 - pass => array('value1', 'value2', ...)
default:
$param = MenuItemRoute::cleanParam($token);
MenuItemRoute::getInstance()->route[] = $param;
break;
}
}
$this->data[$this->name]['match_route'] = serialize(MenuItemRoute::getInstance());
$succes = $this->save(null, false);
}
return $success;
}
示例7: fields
/**
* Generates the fields list of an SQL query.
*
* @param Model $model
* @param string $alias Alias tablename
* @param mixed $fields
* @param boolean $quote If false, returns fields array unquoted
* @return array
*/
public function fields(&$model, $alias = null, $fields = array(), $quote = true)
{
if (empty($alias)) {
$alias = $model->alias;
}
if (empty($fields)) {
$fields = array_keys($model->schema());
} elseif (!is_array($fields)) {
$fields = String::tokenize($fields);
}
$fields = array_values(array_filter($fields));
if (!$quote) {
return $fields;
}
$count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
for ($i = 0; $i < $count; $i++) {
if (preg_match('/^\\(.*\\)\\s' . $this->alias . '.*/i', $fields[$i])) {
continue;
} elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
$prepend = '';
if (strpos($fields[$i], 'DISTINCT') !== false) {
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}
$dot = strpos($fields[$i], '.');
if ($dot === false) {
$prefix = !(strpos($fields[$i], ' ') !== false || strpos($fields[$i], '(') !== false);
$fields[$i] = $this->name(($prefix ? $alias . '.' : '') . $fields[$i]);
} else {
$value = array();
$comma = strpos($fields[$i], ',');
if ($comma === false) {
$build = explode('.', $fields[$i]);
if (!Set::numeric($build)) {
$fields[$i] = $this->name($build[0] . '.' . $build[1]);
}
$comma = String::tokenize($fields[$i]);
foreach ($comma as $string) {
if (preg_match('/^[0-9]+\\.[0-9]+$/', $string)) {
$value[] = $string;
} else {
$build = explode('.', $string);
$value[] = $this->name(trim($build[0]) . '.' . trim($build[1]));
}
}
$fields[$i] = implode(', ', $value);
}
}
$fields[$i] = $prepend . $fields[$i];
} elseif (preg_match('/\\(([\\.\\w]+)\\)/', $fields[$i], $field)) {
if (isset($field[1])) {
if (strpos($field[1], '.') === false) {
$field[1] = $this->name($alias . '.' . $field[1]);
} else {
$field[0] = explode('.', $field[1]);
if (!Set::numeric($field[0])) {
$field[0] = implode('.', array_map(array($this, 'name'), $field[0]));
$fields[$i] = preg_replace('/\\(' . $field[1] . '\\)/', '(' . $field[0] . ')', $fields[$i], 1);
}
}
}
}
}
}
return array_unique($fields);
}
示例8: extractPath
function extractPath($data, $path = null)
{
if (empty($path)) {
return $data;
}
if (is_object($data)) {
$data = get_object_vars($data);
}
if (!is_array($path)) {
if (!class_exists('String')) {
App::import('Core', 'String');
}
$parts = String::tokenize($path, '.', '{', '}');
} else {
$parts = $path;
}
if (!is_array($data)) {
return array();
}
$tmp = array();
if (empty($parts) || !is_array($parts)) {
return array();
}
$key = reset($parts);
$tmpPath = array_slice($parts, 1);
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
if (isset($data[intval($key)])) {
$tmp[intval($key)] = $data[intval($key)];
} else {
return array();
}
} elseif ($key === '{n}') {
foreach ($data as $j => $val) {
if (is_int($j)) {
$tmp[$j] = $val;
}
}
} elseif ($key === '{s}') {
foreach ($data as $j => $val) {
if (is_string($j)) {
$tmp[$j] = $val;
}
}
} elseif (false !== strpos($key, '{') && false !== strpos($key, '}')) {
$pattern = substr($key, 1, -1);
foreach ($data as $j => $val) {
if (preg_match('/^' . $pattern . '/s', $j) !== 0) {
$tmp[$j] = $val;
}
}
} else {
if (isset($data[$key])) {
$tmp[$key] = $data[$key];
} else {
return array();
}
}
$res = array();
if (!empty($tmpPath)) {
foreach ($tmp as $key => $val) {
$res2 = Migration::extractPath($val, $tmpPath);
foreach ($res2 as $key2 => $val2) {
$res[$key . '.' . $key2] = $val2;
}
}
} else {
return $tmp;
}
return $res;
}
示例9: _connectedLike
/**
* Form AND/OR query array using String::tokenize to separate
* search terms by or/and connectors.
*
* @param mixed $value
* @param array $field
* @param string $fieldName
* @return array Conditions
*/
protected function _connectedLike($value, $field, $fieldName, $likeMethod = 'LIKE')
{
$or = array();
$orValues = String::tokenize($value, $field['connectorOr']);
foreach ($orValues as $orValue) {
$andValues = String::tokenize($orValue, $field['connectorAnd']);
$and = array();
foreach ($andValues as $andValue) {
$and[] = array($fieldName . " " . $likeMethod => $field['before'] . $andValue . $field['after']);
}
$or[] = array('AND' => $and);
}
return array('OR' => $or);
}
示例10: insert
/**
* Insert $values into an array with the given $path. You can use
* `{n}` and `{s}` elements to insert $data multiple times.
*
* @param array $data The data to insert into.
* @param string $path The path to insert at.
* @param array $values The values to insert.
* @return array The data with $values inserted.
*/
public static function insert(array $data, $path, $values = null)
{
if (strpos($path, '[') === false) {
$tokens = explode('.', $path);
} else {
$tokens = String::tokenize($path, '.', '[', ']');
}
if (strpos($path, '{') === false && strpos($path, '[') === false) {
return self::_simpleOp('insert', $data, $tokens, $values);
}
$token = array_shift($tokens);
$nextPath = implode('.', $tokens);
list($token, $conditions) = self::_splitConditions($token);
foreach ($data as $k => $v) {
if (self::_matchToken($k, $token)) {
if ($conditions && self::_matches($v, $conditions)) {
$data[$k] = array_merge($v, $values);
continue;
}
if (!$conditions) {
$data[$k] = self::insert($v, $nextPath, $values);
}
}
}
return $data;
}
示例11: fields
/**
* Generates the fields list of an SQL query.
*
* @param Model $model
* @param string $alias Alias tablename
* @param mixed $fields
* @param boolean $quote If false, returns fields array unquoted
* @return array
* @access public
*/
function fields(&$model, $alias = null, $fields = array(), $quote = true)
{
if (empty($alias)) {
$alias = $model->alias;
}
$cacheKey = array($model->useDbConfig, $model->table, array_keys($model->schema()), $model->name, $model->getVirtualField(), $alias, $fields, $quote);
$cacheKey = crc32(serialize($cacheKey));
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
return $return;
}
$allFields = empty($fields);
if ($allFields) {
$fields = array_keys($model->schema());
} elseif (!is_array($fields)) {
$fields = String::tokenize($fields);
}
$fields = array_values(array_filter($fields));
$allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields);
$virtual = array();
$virtualFields = $model->getVirtualField();
if (!empty($virtualFields)) {
$virtualKeys = array_keys($virtualFields);
foreach ($virtualKeys as $field) {
$virtualKeys[] = $model->alias . '.' . $field;
}
$virtual = $allFields ? $virtualKeys : array_intersect($virtualKeys, $fields);
foreach ($virtual as $i => $field) {
if (strpos($field, '.') !== false) {
$virtual[$i] = str_replace($model->alias . '.', '', $field);
}
$fields = array_diff($fields, array($field));
}
$fields = array_values($fields);
}
if (!$quote) {
if (!empty($virtual)) {
$fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual));
}
return $fields;
}
$count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
for ($i = 0; $i < $count; $i++) {
if (is_string($fields[$i]) && in_array($fields[$i], $virtual)) {
unset($fields[$i]);
continue;
}
if (is_object($fields[$i]) && isset($fields[$i]->type) && $fields[$i]->type === 'expression') {
$fields[$i] = $fields[$i]->value;
} elseif (preg_match('/^\\(.*\\)\\s' . $this->alias . '.*/i', $fields[$i])) {
continue;
} elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
$prepend = '';
if (strpos($fields[$i], 'DISTINCT') !== false) {
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}
$dot = strpos($fields[$i], '.');
if ($dot === false) {
$prefix = !(strpos($fields[$i], ' ') !== false || strpos($fields[$i], '(') !== false);
$fields[$i] = $this->name(($prefix ? $alias . '.' : '') . $fields[$i]);
} else {
$value = array();
$comma = strpos($fields[$i], ',');
if ($comma === false) {
$build = explode('.', $fields[$i]);
if (!Set::numeric($build)) {
$fields[$i] = $this->name(implode('.', $build));
}
}
}
$fields[$i] = $prepend . $fields[$i];
} elseif (preg_match('/\\(([\\.\\w]+)\\)/', $fields[$i], $field)) {
if (isset($field[1])) {
if (strpos($field[1], '.') === false) {
$field[1] = $this->name($alias . '.' . $field[1]);
} else {
$field[0] = explode('.', $field[1]);
if (!Set::numeric($field[0])) {
$field[0] = implode('.', array_map(array(&$this, 'name'), $field[0]));
$fields[$i] = preg_replace('/\\(' . $field[1] . '\\)/', '(' . $field[0] . ')', $fields[$i], 1);
}
}
}
}
}
}
if (!empty($virtual)) {
$fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual));
}
//.........这里部分代码省略.........
示例12: testTokenize
/**
* testTokenize method
*
* @return void
*/
public function testTokenize()
{
$result = String::tokenize('A,(short,boring test)');
$expected = array('A', '(short,boring test)');
$this->assertEquals($expected, $result);
$result = String::tokenize('A,(short,more interesting( test)');
$expected = array('A', '(short,more interesting( test)');
$this->assertEquals($expected, $result);
$result = String::tokenize('A,(short,very interesting( test))');
$expected = array('A', '(short,very interesting( test))');
$this->assertEquals($expected, $result);
$result = String::tokenize('"single tag"', ' ', '"', '"');
$expected = array('"single tag"');
$this->assertEquals($expected, $result);
$result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"');
$expected = array('tagA', '"single tag"', 'tagB');
$this->assertEquals($expected, $result);
}
示例13: classicExtract
/**
* Gets a value from an array or object that is contained in a given path using an array path syntax, i.e.:
* "{n}.Person.{[a-z]+}" - Where "{n}" represents a numeric key, "Person" represents a string literal,
* and "{[a-z]+}" (i.e. any string literal enclosed in brackets besides {n} and {s}) is interpreted as
* a regular expression.
*
* @param array $data Array from where to extract
* @param mixed $path As an array, or as a dot-separated string.
* @return array Extracted data
* @access public
* @static
*/
function classicExtract($data, $path = null)
{
if (empty($path)) {
return $data;
}
if (is_object($data)) {
$data = get_object_vars($data);
}
if (!is_array($data)) {
return $data;
}
if (!is_array($path)) {
if (!class_exists('String')) {
App::import('Core', 'String');
}
$path = String::tokenize($path, '.', '{', '}');
}
$tmp = array();
if (!is_array($path) || empty($path)) {
return null;
}
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
if (isset($data[intval($key)])) {
$data = $data[intval($key)];
} else {
return null;
}
} elseif ($key === '{n}') {
foreach ($data as $j => $val) {
if (is_int($j)) {
$tmpPath = array_slice($path, $i + 1);
if (empty($tmpPath)) {
$tmp[] = $val;
} else {
$tmp[] = Set::classicExtract($val, $tmpPath);
}
}
}
return $tmp;
} elseif ($key === '{s}') {
foreach ($data as $j => $val) {
if (is_string($j)) {
$tmpPath = array_slice($path, $i + 1);
if (empty($tmpPath)) {
$tmp[] = $val;
} else {
$tmp[] = Set::classicExtract($val, $tmpPath);
}
}
}
return $tmp;
} elseif (false !== strpos($key, '{') && false !== strpos($key, '}')) {
$pattern = substr($key, 1, -1);
foreach ($data as $j => $val) {
if (preg_match('/^' . $pattern . '/s', $j) !== 0) {
$tmpPath = array_slice($path, $i + 1);
if (empty($tmpPath)) {
$tmp[$j] = $val;
} else {
$tmp[$j] = Set::classicExtract($val, $tmpPath);
}
}
}
return $tmp;
} else {
if (isset($data[$key])) {
$data = $data[$key];
} else {
return null;
}
}
}
return $data;
}
示例14: beforeFind
/**
* beforeFind Callback
*
* @param Model $Model Model find is being run on.
* @param array $query Array of Query parameters.
* @return array Modified query
*/
public function beforeFind(Model $Model, $query)
{
$this->runtime[$Model->alias]['virtualFields'] = $Model->virtualFields;
$locale = $this->_getLocale($Model);
if (empty($locale)) {
return $query;
}
$db = $Model->getDataSource();
$RuntimeModel = $this->translateModel($Model);
if (!empty($RuntimeModel->tablePrefix)) {
$tablePrefix = $RuntimeModel->tablePrefix;
} else {
$tablePrefix = $db->config['prefix'];
}
$joinTable = new StdClass();
$joinTable->tablePrefix = $tablePrefix;
$joinTable->table = $RuntimeModel->table;
$joinTable->schemaName = $RuntimeModel->getDataSource()->getSchemaName();
$this->_joinTable = $joinTable;
$this->_runtimeModel = $RuntimeModel;
if (is_string($query['fields']) && $query['fields'] === "COUNT(*) AS {$db->name('count')}") {
$query['fields'] = "COUNT(DISTINCT({$db->name($Model->escapeField())})) {$db->alias}count";
$query['joins'][] = array('type' => 'INNER', 'alias' => $RuntimeModel->alias, 'table' => $joinTable, 'conditions' => array($Model->escapeField() => $db->identifier($RuntimeModel->escapeField('foreign_key')), $RuntimeModel->escapeField('model') => $Model->name, $RuntimeModel->escapeField('locale') => $locale));
$conditionFields = $this->_checkConditions($Model, $query);
foreach ($conditionFields as $field) {
$query = $this->_addJoin($Model, $query, $field, $field, $locale);
}
unset($this->_joinTable, $this->_runtimeModel);
return $query;
} elseif (is_string($query['fields'])) {
$query['fields'] = String::tokenize($query['fields']);
}
$fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']);
$addFields = array();
if (empty($query['fields'])) {
$addFields = $fields;
} elseif (is_array($query['fields'])) {
$isAllFields = in_array($Model->alias . '.' . '*', $query['fields']) || in_array($Model->escapeField('*'), $query['fields']);
foreach ($fields as $key => $value) {
$field = is_numeric($key) ? $value : $key;
if ($isAllFields || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
$addFields[] = $field;
}
}
}
$this->runtime[$Model->alias]['virtualFields'] = $Model->virtualFields;
if ($addFields) {
foreach ($addFields as $_f => $field) {
$aliasField = is_numeric($_f) ? $field : $_f;
foreach (array($aliasField, $Model->alias . '.' . $aliasField) as $_field) {
$key = array_search($_field, (array) $query['fields']);
if ($key !== false) {
unset($query['fields'][$key]);
}
}
$query = $this->_addJoin($Model, $query, $field, $aliasField, $locale);
}
}
$this->runtime[$Model->alias]['beforeFind'] = $addFields;
unset($this->_joinTable, $this->_runtimeModel);
return $query;
}
示例15: __parseEventName
private function __parseEventName($eventName)
{
App::import('Core', 'String');
$eventTokens = String::tokenize($eventName, '.');
$scope = 'Global';
$event = $eventTokens[0];
if (count($eventTokens) > 1) {
list($scope, $event) = $eventTokens;
}
return compact('scope', 'event');
}