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


PHP Set::matches方法代码示例

本文整理汇总了PHP中Set::matches方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::matches方法的具体用法?PHP Set::matches怎么用?PHP Set::matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set::matches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRelatedFind

 function testRelatedFind()
 {
     $result = $this->TestRegion->find('all', array('contain' => 'Country'));
     $this->assertTrue(Set::matches('/TestRegion[title=Sydney]/../Country[title=Australia]', $result));
     $this->assertFalse(Set::matches('/TestRegion[title=Sydney]/../Country[title=United States]', $result));
     $this->assertTrue(Set::matches('/TestRegion[title=New York]/../Country[title=United States]', $result));
 }
开发者ID:asavoy,项目名称:country_plugin,代码行数:7,代码来源:country.test.php

示例2: testFindScoped

 function testFindScoped()
 {
     $this->User->Behaviors->attach('Scope.Scope', array('field' => 'site_id', 'value' => 1));
     $result = $this->User->find('all');
     $expected = array('evilbloodydemon@gmail.com', 'vasya-juikin@gmail.com', 'medvedev@gmail.com');
     $this->assertEqual($expected, Set::extract('/User/email', $result));
     $result = $this->User->find('all', array('conditions' => array('User.email' => 'evilbloodydemon@gmail.com', 'User.site_id' => 2)));
     $this->assertTrue(Set::matches('/User[id=1]', $result));
 }
开发者ID:evilbloodydemon,项目名称:cakephp-scope,代码行数:9,代码来源:scope.test.php

示例3: testFind

 function testFind()
 {
     $Model =& ClassRegistry::init('Song');
     $Model->Behaviors->attach('Media.Coupler', $this->_behaviorSettings);
     $result = $Model->find('all');
     $this->assertEqual(count($result), 4);
     /* Virtual */
     $result = $Model->findById(1);
     $this->assertTrue(Set::matches('/Song/file', $result));
     $this->assertEqual($result['Song']['file'], $this->file0);
 }
开发者ID:Techmentis,项目名称:flinkiso-lite,代码行数:11,代码来源:coupler.test.php

示例4: testFind

 function testFind()
 {
     $Model =& ClassRegistry::init('Song');
     $Model->Behaviors->attach('Media.Media', $this->_behaviorSettings);
     $result = $Model->find('all');
     $this->assertEqual(count($result), 3);
     /* Virtual */
     $result = $Model->findById(1);
     $this->assertTrue(Set::matches('/Song/size', $result));
     $this->assertTrue(Set::matches('/Song/mime_type', $result));
 }
开发者ID:essemme,项目名称:media,代码行数:11,代码来源:media.test.php

示例5: testFind

 public function testFind()
 {
     $Model = ClassRegistry::init('Song');
     $Model->Behaviors->load('Media.Coupler', $this->behaviorSettings['Coupler']);
     $Model->Behaviors->load('Media.Meta', $this->behaviorSettings['Meta']);
     $result = $Model->find('all');
     $this->assertEqual(count($result), 4);
     /* Virtual */
     $result = $Model->findById(1);
     $this->assertTrue(Set::matches('/Song/size', $result));
     $this->assertTrue(Set::matches('/Song/mime_type', $result));
 }
开发者ID:miznokruge,项目名称:base-cake,代码行数:12,代码来源:MetaBehaviorTest.php

示例6: testFind

 public function testFind()
 {
     $Model = ClassRegistry::init('Song');
     $Model->Behaviors->load('Media.Coupler', $this->behaviorSettings);
     $result = $Model->find('all');
     $this->assertEqual(count($result), 4);
     $file = $this->Data->getFile(array('image-png.png' => $this->Data->settings['static'] . 'img/image-png.png'));
     /* Virtual */
     $result = $Model->findById(1);
     $this->assertTrue(Set::matches('/Song/file', $result));
     $this->assertEqual($result['Song']['file'], $file);
 }
开发者ID:miznokruge,项目名称:base-cake,代码行数:12,代码来源:CouplerBehaviorTest.php

示例7: afterFind

 function afterFind(&$Model, $results, $primary)
 {
     extract($this->settings[$Model->alias]);
     if (!Set::matches('/' . $with, $results)) {
         return;
     }
     foreach ($results as $i => $item) {
         foreach ($item[$with] as $field) {
             $results[$i][$Model->alias][$field['key']] = $field['val'];
         }
     }
     return $results;
 }
开发者ID:jimiyash,项目名称:debuggable-scraps,代码行数:13,代码来源:expandable.php

示例8: testSave

 function testSave()
 {
     $this->File->id = 1;
     $this->File->set('colors', 16);
     $this->File->save();
     $r = $this->File->find('first');
     $this->assertTrue(Set::matches('/FileTestModel[1]/.[colors=16]', $r));
     $this->assertTrue(Set::matches('/FileTestModel[1]/.[page_id=1]', $r));
     $this->File->id = 2;
     $this->File->set('width', 640);
     $this->File->set('height', 480);
     $this->File->save();
     $r = $this->File->find('first');
     $this->assertTrue(Set::matches('/FileTestModel[1]/.[width=640]', $r));
     $this->assertTrue(Set::matches('/FileTestModel[1]/.[height=480]', $r));
 }
开发者ID:jimiyash,项目名称:debuggable-scraps,代码行数:16,代码来源:expandable.test.php

示例9: _recursiveFilter

 /**
  * @param $filter
  * @param $value
  * @param $element
  * @param string $path
  * @return array|mixed
  */
 protected function _recursiveFilter($filter, $value, $element, $path = '')
 {
     if (is_array($value)) {
         $cleanValues = array();
         $parent = $path;
         foreach ($value as $k => $v) {
             $path = $parent !== '' ? $parent . '.' . $k : $k;
             $cleanValues[$k] = $this->_recursiveFilter($filter, $v, $element, $path);
         }
         return $cleanValues;
     } else {
         if ($element === '__ALL__' || $element === $path || Set::matches($element, Set::expand(array($path => '')))) {
             return call_user_func($filter, $value);
         } else {
             return $value;
         }
     }
 }
开发者ID:tsmsogn,项目名称:datafilter,代码行数:25,代码来源:DatafilterComponent.php

示例10: afterFind

 /**
  * after a find this will join on the extra fields to the array so
  * they are available in the view.
  *
  * @var $Model object the model that did the find
  * @var $results array what was found
  * @var $primary if its the main model doing the call
  *
  * @return array the modified find data
  */
 public function afterFind(&$Model, $results, $primary)
 {
     extract($this->settings[$Model->alias]);
     if (!Set::matches('/' . $with, $results)) {
         return;
     }
     foreach ($results as $i => $item) {
         $done = false;
         $keys = array_keys($item);
         foreach ($keys as $key) {
             if (strstr($key, 'Attribute')) {
                 $item[$Model->alias][$item[$key]['key']] = $item[$key]['val'];
                 $done = true;
             }
         }
         if ($done) {
             continue;
         }
         foreach ($item[$with] as $field) {
             $results[$i][$Model->alias][$field['key']] = $field['val'];
         }
     }
     return $results;
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:34,代码来源:ExpandableBehavior.php

示例11: __checkConditions

 /**
  * Private helper method to check conditions.
  *
  * @param array $record
  * @param array $conditions
  * @return bool
  */
 private function __checkConditions($record, $conditions, $model)
 {
     $result = true;
     foreach ($conditions as $name => $value) {
         $alias = $model->alias;
         if (strpos($name, '.') !== false) {
             list($alias, $name) = explode('.', $name);
         }
         if (strtolower($name) === 'or') {
             $cond = $value;
             $result = false;
             foreach ($cond as $name => $value) {
                 if (Set::matches($this->__createRule($name, $value), $record[$alias])) {
                     return true;
                 }
             }
         } else {
             if (!Set::matches($this->__createRule($name, $value), $record[$alias])) {
                 return false;
             }
         }
     }
     return $result;
 }
开发者ID:kishoreks,项目名称:cakento,代码行数:31,代码来源:csv_source.php

示例12: testMatches

 /**
  * testMatches method
  *
  * @access public
  * @return void
  */
 function testMatches()
 {
     $a = array(array('Article' => array('id' => 1, 'title' => 'Article 1')), array('Article' => array('id' => 2, 'title' => 'Article 2')), array('Article' => array('id' => 3, 'title' => 'Article 3')));
     $this->assertTrue(Set::matches(array('id=2'), $a[1]['Article']));
     $this->assertFalse(Set::matches(array('id>2'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('id>=2'), $a[1]['Article']));
     $this->assertFalse(Set::matches(array('id>=3'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('id<=2'), $a[1]['Article']));
     $this->assertFalse(Set::matches(array('id<2'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('id>1'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('id>1', 'id<3', 'id!=0'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('3'), null, 3));
     $this->assertTrue(Set::matches(array('5'), null, 5));
     $this->assertTrue(Set::matches(array('id'), $a[1]['Article']));
     $this->assertTrue(Set::matches(array('id', 'title'), $a[1]['Article']));
     $this->assertFalse(Set::matches(array('non-existant'), $a[1]['Article']));
     $this->assertTrue(Set::matches('/Article[id=2]', $a));
     $this->assertFalse(Set::matches('/Article[id=4]', $a));
     $this->assertTrue(Set::matches(array(), $a));
 }
开发者ID:subh,项目名称:raleigh-workshop-08,代码行数:26,代码来源:set.test.php

示例13: beforeFind

 function beforeFind(&$Model, $query)
 {
     if (isset($query['nofilter']) && $query['nofilter'] === true) {
         return $query;
     }
     if (method_exists($Model, 'beforeDataFilter')) {
         $callbackOptions['values'] = $this->_filterValues[$Model->alias];
         $callbackOptions['settings'] = $this->settings[$Model->alias];
         if (!$Model->beforeDataFilter($query, $callbackOptions)) {
             return $query;
         }
     }
     if (!isset($this->settings[$Model->alias])) {
         return $query;
     }
     $settings = $this->settings[$Model->alias];
     $values = $this->_filterValues[$Model->alias];
     foreach ($settings as $field => $options) {
         $fieldModelName = $Model->alias;
         $fieldName = $field;
         if (strpos($field, '.') !== false) {
             list($fieldModelName, $fieldName) = explode('.', $field);
         }
         if (!isset($values[$fieldModelName][$fieldName]) && isset($options['default'])) {
             $values[$fieldModelName][$fieldName] = $options['default'];
         }
         if ($options['required'] && !isset($values[$fieldModelName][$fieldName])) {
             // TODO: implement a bit of a user friendly handling of this scenario..
             trigger_error(__('No value present for required field %s and default value not present', $field));
             return;
         }
         if (!isset($values[$fieldModelName][$fieldName]) || is_null($values[$fieldModelName][$fieldName])) {
             // no value to filter with, just skip this field
             continue;
         }
         // the value we get as condition and where it comes from is not the same as the
         // model and field we're using to filter the data
         $filterByField = $fieldName;
         $filterByModel = $Model->alias;
         $relationType = null;
         if ($fieldModelName != $Model->name) {
             $relationTypes = array('hasMany', 'hasOne');
             foreach ($relationTypes as $type) {
                 if (isset($Model->{$type}) && isset($Model->{$type}[$fieldModelName])) {
                     $filterByModel = 'Filter' . $fieldModelName;
                     $relationType = $type;
                     break;
                 }
             }
         }
         if (isset($options['filterField'])) {
             if (strpos($options['filterField'], '.') !== false) {
                 list($tmpFieldModel, $tmpFieldName) = explode('.', $options['filterField']);
                 $filterByField = $tmpFieldName;
             } else {
                 $filterByField = $options['filterField'];
             }
         }
         $realFilterField = sprintf('%s.%s', $filterByModel, $filterByField);
         if (isset($Model->{$relationType}) && isset($Model->{$relationType}[$fieldModelName])) {
             $relatedModel = $Model->{$fieldModelName};
             $relatedModelAlias = 'Filter' . $relatedModel->alias;
             if (!Set::matches(sprintf('/joins[alias=%s]', $relatedModelAlias), $query)) {
                 $conditions = array();
                 if (isset($Model->{$relationType}[$fieldModelName]['foreignKey']) && $Model->{$relationType}[$fieldModelName]['foreignKey']) {
                     $conditions[] = sprintf('%s.%s = %s.%s', $Model->alias, $Model->primaryKey, $relatedModelAlias, $Model->{$relationType}[$fieldModelName]['foreignKey']);
                 }
                 // merge any custom conditions from the relation, but change
                 // the alias to our $relatedModelAlias
                 if (isset($Model->{$relationType}[$fieldModelName]['conditions']) && !empty($Model->{$relationType}[$fieldModelName]['conditions'])) {
                     $customConditions = $Model->{$relationType}[$fieldModelName]['conditions'];
                     if (!is_array($Model->{$relationType}[$fieldModelName]['conditions'])) {
                         $customConditions = array($customConditions);
                     }
                     $filterConditions = preg_replace(sprintf('#(?<![A-Za-z])%s(?![A-Za-z])#', $relatedModel->alias), $relatedModelAlias, $customConditions);
                     $conditions = array_merge($conditions, $filterConditions);
                 }
                 $query['joins'][] = array('table' => $relatedModel->table, 'alias' => $relatedModelAlias, 'type' => 'INNER', 'conditions' => $conditions);
             }
         }
         // TODO: handle NULLs?
         switch ($options['type']) {
             case 'text':
                 if (strlen(trim(strval($values[$fieldModelName][$fieldName]))) == 0) {
                     continue;
                 }
                 switch ($options['condition']) {
                     case 'like':
                     case 'contains':
                         $query['conditions'][$realFilterField . ' like'] = '%' . $values[$fieldModelName][$fieldName] . '%';
                         break;
                     case 'startswith':
                         $query['conditions'][$realFilterField . ' like'] = $values[$fieldModelName][$fieldName] . '%';
                         break;
                     case 'endswith':
                         $query['conditions'][$realFilterField . ' like'] = '%' . $values[$fieldModelName][$fieldName];
                         break;
                     case '=':
                         $query['conditions'][$realFilterField] = $values[$fieldModelName][$fieldName];
                         break;
//.........这里部分代码省略.........
开发者ID:ricardobylife,项目名称:Zhen-CRM,代码行数:101,代码来源:FilteredBehavior.php

示例14: __assertMatches

 /**
  * Convenience function to assert Matches using Set::matches
  *
  * @param string $pattern
  * @param string $object
  * @param string $message
  * @return void
  */
 private function __assertMatches($pattern, $object, $message = '')
 {
     return $this->assertTrue(Set::matches($pattern, $object), $message);
     return true;
     return $this->assert(new TrueExpectation(), Set::matches($pattern, $object), $message);
 }
开发者ID:tetsuo111,项目名称:cakephp,代码行数:14,代码来源:InheritableTest.php

示例15: afterFind

 /**
  * Standard afterFind() callback
  * Inject the expandable data (as fields)
  *
  * @param object Model $Model
  * @param mixed $results
  * @param boolean $primary
  *
  * @return mixed $results
  */
 public function afterFind(Model $Model, $results, $primary)
 {
     $settings = $this->settings[$Model->alias];
     if (!empty($settings['with'])) {
         $with = $settings['with'];
         if (!Set::matches('/' . $with, $results)) {
             return;
         }
         foreach (array_keys($results) as $i) {
             foreach (array_keys($results[$i][$with]) as $j) {
                 $key = $results[$i][$with][$j]['key'];
                 $value = $results[$i][$with][$j]['value'];
                 $results[$i][$Model->alias][$key] = $value;
             }
         }
     }
     return $results;
 }
开发者ID:Marcin11,项目名称:_mojePanstwo-Portal,代码行数:28,代码来源:ExpandableBehavior.php


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