HosipLan

Untitled

Oct 9th, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1.     /**
  2.      * @param array $collection
  3.      * @param array $lists
  4.      * @param array $mappers
  5.      * @param boolean $allowDuplications
  6.      */
  7.     public function assertContainsCombinations($collection, array $lists, array $mappers, $allowDuplications = TRUE)
  8.     {
  9.         $mappers = array_map('callback', $mappers);
  10.         $this->assertSame(count($lists), count($mappers), "Count of given lists equals to count of given mappers");
  11.  
  12.         $found = array_fill_keys(range(0, count($mappers)), array());
  13.         foreach ($collection as $item) {
  14.             foreach ($mappers as $i => $mapper) {
  15.                 $found[$i][] = $mapper($item);
  16.             }
  17.         }
  18.  
  19.         $combinations = array();
  20.  
  21. //      $counts = array_map('array_count_values', $found);
  22. //      dump($counts);
  23.     }
  24.  
  25.  
  26. // použití
  27.  
  28.  
  29.  
  30.         $actions = array('access', 'view', 'edit', 'create', 'delete');
  31.         $resources = array('identity', 'article', 'comment', 'thread');
  32.         $this->assertContainsCombinations($permissions, array($actions, $resources),
  33.                 array(
  34.                     function (BasePermission $permission) {
  35.                         return $permission->getPrivilege()->getAction()->getName();
  36.                     },
  37.                     function (BasePermission $permission) {
  38.                         return $permission->getPrivilege()->getResource()->getName();
  39.                     }
  40.                 ),
  41.                 FALSE
  42.             );
  43.  
Advertisement
Add Comment
Please, Sign In to add comment