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


PHP String::tokenize方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:ambagasdowa,项目名称:kml,代码行数:9,代码来源:acl_reflector.php

示例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');
     }
 }
开发者ID:dereuromark,项目名称:cakephp-setup,代码行数:54,代码来源:IndentShell.php

示例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')));
 }
开发者ID:rodrigovmachado,项目名称:acl_caching,代码行数:53,代码来源:acl_controller.php

示例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];
 }
开发者ID:hernandes,项目名称:mithos,代码行数:45,代码来源:Hash.php

示例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);
 }
开发者ID:oguzhanaltan,项目名称:Cakephp-ACL-Management-And-Auth,代码行数:41,代码来源:AclsController.php

示例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;
 }
开发者ID:anler,项目名称:Cpanel,代码行数:36,代码来源:cpanel_menu.php

示例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);
 }
开发者ID:evrard,项目名称:cakephp2x,代码行数:76,代码来源:dbo_source.php

示例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;
 }
开发者ID:kevthunder,项目名称:cake-migration,代码行数:70,代码来源:migration.php

示例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);
 }
开发者ID:klapp303,项目名称:budget,代码行数:23,代码来源:SearchableBehavior.php

示例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;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:35,代码来源:gumm_hash.php

示例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));
     }
//.........这里部分代码省略.........
开发者ID:sathishkumarb,项目名称:HVMS,代码行数:101,代码来源:dbo_source.php

示例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);
 }
开发者ID:nabeelio,项目名称:CakePHP-Base,代码行数:23,代码来源:StringTest.php

示例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;
 }
开发者ID:BGCX067,项目名称:fake-as3-svn-to-git,代码行数:87,代码来源:set.php

示例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;
 }
开发者ID:saihe,项目名称:reservation,代码行数:69,代码来源:TranslateBehavior.php

示例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');
 }
开发者ID:rchavik,项目名称:infinitas,代码行数:11,代码来源:events.php


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