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


PHP Set::isEqual方法代码示例

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


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

示例1: testIsEqual

 /**
  * testIsEqual method
  *
  * @access public
  * @return void
  */
 function testIsEqual()
 {
     $a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
     $b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'));
     $this->assertTrue(Set::isEqual($a, $a));
     $this->assertTrue(Set::isEqual($b, $b));
     $this->assertFalse(Set::isEqual($a, $b));
     $this->assertFalse(Set::isEqual($b, $a));
 }
开发者ID:subh,项目名称:raleigh-workshop-08,代码行数:15,代码来源:set.test.php

示例2: beforeSave

 /**
  * Sets update actions and their conditions which get executed in after save,
  * affects model->data when necessary
  *
  * @param Model $model Model object that method is triggered on
  * @return boolean Always true otherwise model will not save
  */
 public function beforeSave(&$model)
 {
     $this->_update[$model->alias] = array();
     // Sets new order and new groups from model->data
     $this->_setNewOrder($model);
     $this->_setNewGroups($model);
     $orderField = $this->settings[$model->alias]['order_field'];
     $escapedOrderField = $this->settings[$model->alias]['escaped_order_field'];
     // Adding
     if (!$model->id) {
         // Order not specified
         if (!isset($this->_newOrder[$model->alias])) {
             // Insert at end of list
             $model->data[$model->alias][$orderField] = $this->_getHighestOrder($model, $this->_newGroups[$model->alias]) + 1;
             // Order specified
         } else {
             // The updateAll called in afterSave uses old groups values as default
             // conditions to restrict which records are updated, so set old groups
             // to new groups as old isn't set.
             $this->_oldGroups[$model->alias] = $this->_newGroups[$model->alias];
             // Insert and increment order of records it's inserted before
             $this->_update[$model->alias][] = array('action' => array($escapedOrderField => $escapedOrderField . ' + 1'), 'conditions' => array($escapedOrderField . ' >=' => $this->_newOrder[$model->alias]));
         }
         // Editing
     } else {
         // No action if no new order or group specified
         if (!isset($this->_newOrder[$model->alias]) && !isset($this->_newGroups[$model->alias])) {
             return;
         }
         $this->_setOldOrder($model);
         $this->_setOldGroups($model);
         // No action if new and old group and order same
         if ($this->_newOrder[$model->alias] == $this->_oldOrder[$model->alias] && Set::isEqual($this->_newGroups[$model->alias], $this->_oldGroups[$model->alias])) {
             return;
         }
         // If changing group
         if ($this->_newGroups[$model->alias] && !Set::isEqual($this->_newGroups[$model->alias], $this->_oldGroups[$model->alias])) {
             // Decrement records in old group with higher order than moved record old order
             $this->_update[$model->alias][] = array('action' => array($escapedOrderField => $escapedOrderField . ' - 1'), 'conditions' => array($escapedOrderField . ' >=' => $this->_oldOrder[$model->alias]));
             // Order not specified
             if (!isset($this->_newOrder[$model->alias])) {
                 // Insert at end of new group
                 $model->data[$model->alias][$orderField] = $this->_getHighestOrder($model, $this->_newGroups[$model->alias]) + 1;
                 // Order specified
             } else {
                 // Increment records in new group with higher order than moved record new order
                 $this->_update[$model->alias][] = array('action' => array($escapedOrderField => $escapedOrderField . ' + 1'), 'conditions' => array($escapedOrderField . ' >=' => $this->_newOrder[$model->alias]), 'group_values' => $this->_newGroups[$model->alias]);
             }
             // Same group
         } else {
             // If moving up
             if ($this->_newOrder[$model->alias] < $this->_oldOrder[$model->alias]) {
                 // Increment order of those in between
                 $this->_update[$model->alias][] = array('action' => array($escapedOrderField => $escapedOrderField . ' + 1'), 'conditions' => array(array($escapedOrderField . ' >=' => $this->_newOrder[$model->alias]), array($escapedOrderField . ' <' => $this->_oldOrder[$model->alias])));
                 // Moving down
             } else {
                 // Decrement order of those in between
                 $this->_update[$model->alias][] = array('action' => array($escapedOrderField => $escapedOrderField . ' - 1'), 'conditions' => array(array($escapedOrderField . ' >' => $this->_oldOrder[$model->alias]), array($escapedOrderField . ' <=' => $this->_newOrder[$model->alias])));
             }
         }
     }
     return true;
 }
开发者ID:peterfarsinsen,项目名称:sequence,代码行数:70,代码来源:sequence.php

示例3: set_utility

    function set_utility($method = 'options')
    {
        if ($method == 'merge') {
            $A1 = array('Model' => array('f1' => '1', 'f2' => '1', 'f3' => '1'));
            $A2 = array('Model' => array('f3' => '2', 'f4' => '1', 'f5' => '1'));
            $merged_arrays = array_merge($A1, $A2);
            $added_arrays = $A1 + $A2;
            $merged_recursive = array_merge_recursive($A1, $A2);
            function array_update($arr, $ins)
            {
                if (is_array($arr) && is_array($ins)) {
                    foreach ($ins as $k => $v) {
                        if (isset($arr[$k]) && is_array($v) && is_array($arr[$k])) {
                            $arr[$k] = array_update($arr[$k], $v);
                        } else {
                            $arr[$k] = $v;
                        }
                    }
                } elseif (!is_array($arr) && (strlen($arr) == 0 || $arr == 0)) {
                    $arr = $ins;
                }
                return $arr;
            }
            $array_update = array_update($A1, $A2);
            $set_merge = Set::merge($A1, $A2);
            $REPORT = array('A1' => $A1, 'A2' => $A2, 'merged' => $merged_arrays, 'added' => $added_arrays, 'merged_recursive' => $merged_recursive, 'array_update' => $array_update, 'Set::merge' => $set_merge, 'Set::isEqual($array_update, $set_merge)' => Set::isEqual($array_update, $set_merge));
        } elseif ($method == 'diff') {
            $set = 'a.b.c';
            $DiffList = array('a' => 0, 'a.b' => 0, 'a.b.c' => 1, 'a.b.c.x' => 1, 'a.b.x' => 0, 'a.x' => 0, 'x' => 0, 'b' => 0, 'b.c' => 0, '*' => 1, '*.b.c' => 1, '*.x' => 0);
            $REPORT['results'] = '';
            foreach ($DiffList as $diff_set => $expect) {
                $SetArray = explode('.', $set);
                $DiffArray = explode('.', $diff_set);
                $depth_delta = count($SetArray) - count($DiffArray);
                if ($depth_delta > 0) {
                    foreach (range(1, $depth_delta) as $n) {
                        $DiffArray[] = $DiffArray[count($DiffArray) - 1] == '*' ? '*' : '!';
                    }
                }
                $SetDiff = Set::diff($SetArray, $DiffArray);
                $mismatch = 0;
                if ($SetDiff) {
                    foreach ($SetArray as $n => $x) {
                        if (isset($SetDiff[$n]) && $DiffArray[$n] != '*') {
                            $mismatch = "{$n} => {$x}";
                        }
                    }
                }
                $has_privilege = (int) (!(bool) $mismatch);
                $REPORT[$diff_set] = array('pass' => (int) ($has_privilege == $expect), 'expect' => $expect, 'result' => $has_privilege, 'mismatch' => $mismatch, "{$set} diff {$diff_set}" => $SetDiff);
            }
            $REPORT['results'] = Set::extract('{s}.pass', $REPORT);
            unset($REPORT['results'][0]);
        } else {
            $content = <<<EOMENU
<h3>methods</h3>
<a href="/demo/set_utility/merge">Set::merge</a><br />
<a href="/demo/set_utility/diff">Set::diff</a><br />
EOMENU;
            $this->set('header', 'Gatekeeper Test');
            $this->set('content', $content);
            return $this->render('index');
        }
        $this->set('header', 'Set Examples');
        $this->set('data', $REPORT);
        $this->render('report');
    }
开发者ID:areisv,项目名称:cakewell,代码行数:67,代码来源:demo_controller.php

示例4: setSaveUpdateData

 /**
  * Sets update actions and their conditions which get executed in after save
  *
  * @param AppModel $model
  */
 function setSaveUpdateData(&$model)
 {
     // Sets new order and new groups from model->data
     $this->setNewOrder($model);
     $this->setNewGroups($model);
     // Adding
     if (!$model->id) {
         // Order not specified
         if (!$this->newOrder) {
             // Insert at end of list
             $model->data[$model->alias][$this->orderField] = $this->getHighestOrder($model, $this->newGroups) + 1;
             // Order specified
         } else {
             // The updateAll called in afterSave uses old groups values as default
             // conditions to restrict which records are updated, so set old groups
             // to new groups as old isn't set.
             $this->oldGroups = $this->newGroups;
             // Insert and increment order of records it's inserted before
             $this->update = array('action' => array($this->escapedOrderField => $this->escapedOrderField . ' + 1'), 'conditions' => array($this->escapedOrderField . ' >=' => $this->newOrder));
         }
         // Editing
     } else {
         // No action if no new order or group specified
         if (is_null($this->newOrder) && is_null($this->newGroups)) {
             return;
         }
         $this->setOldOrder($model);
         $this->setOldGroups($model);
         // No action if new and old group and order same
         if ($this->newOrder == $this->oldOrder && Set::isEqual($this->newGroups, $this->oldGroups)) {
             return;
         }
         // If changing group
         if ($this->newGroups && !Set::isEqual($this->newGroups, $this->oldGroups)) {
             // Decrement records in old group with higher order than moved record old order
             $this->update = array('action' => array($this->escapedOrderField => $this->escapedOrderField . ' - 1'), 'conditions' => array($this->escapedOrderField . ' >=' => $this->oldOrder));
             // Insert at end of new group
             $model->data[$model->alias][$this->orderField] = $this->getHighestOrder($model, $this->newGroups) + 1;
             // Same group
         } else {
             // If moving up
             if ($this->newOrder < $this->oldOrder) {
                 // Increment order of those in between
                 $this->update = array('action' => array($this->escapedOrderField => $this->escapedOrderField . ' + 1'), 'conditions' => array(array($this->escapedOrderField . ' >=' => $this->newOrder), array($this->escapedOrderField . ' <' => $this->oldOrder)));
                 // Moving down
             } else {
                 // Decrement order of those in between
                 $this->update = array('action' => array($this->escapedOrderField => $this->escapedOrderField . ' - 1'), 'conditions' => array(array($this->escapedOrderField . ' >' => $this->oldOrder), array($this->escapedOrderField . ' <=' => $this->newOrder)));
             }
         }
     }
 }
开发者ID:peterfarsinsen,项目名称:cakephp,代码行数:57,代码来源:sequence.php

示例5: validateConditions

 function validateConditions(&$Model, $primaryKey)
 {
     if (!empty($this->settings[$Model->alias]['saveOn']['conditions'])) {
         $data = $this->getFieldsForConditions(&$Model, $primaryKey);
         if (isset($data[$Model->alias])) {
             $data = $data[$Model->alias];
         }
         if (Set::isEqual($data, $this->settings[$Model->alias]['saveOn']['conditions'])) {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
开发者ID:namelessnotion,项目名称:activity_feed,代码行数:15,代码来源:activity.php


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