本文整理汇总了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));
}
示例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));
}
示例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);
}
示例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));
}
示例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));
}
示例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);
}
示例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;
}
示例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));
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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));
}
示例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;
//.........这里部分代码省略.........
示例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);
}
示例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;
}