Inheritance: implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate
 protected function mapEntityToConfig(AuthorizationEntity $entity)
 {
     $normalized = [];
     foreach ($entity->getArrayCopy() as $spec => $privileges) {
         preg_match('/^(?P<service>[^:]+)(::(?P<action>.*))?$/', $spec, $matches);
         if (!isset($matches['action'])) {
             $normalized[$matches['service']]['actions']['index'] = $privileges;
         } elseif (preg_match('/^__(?P<type>collection|entity)__$/', $matches['action'], $actionMatches)) {
             $type = $actionMatches['type'];
             $normalized[$matches['service']][$type] = $privileges;
         } else {
             $normalized[$matches['service']]['actions'][$matches['action']] = $privileges;
         }
     }
     return $normalized;
 }
Beispiel #2
0
 /**
  * Determine the base service name for authorization service keys
  *
  * @param AuthorizationEntity $entity
  * @return array
  */
 protected function getBaseServiceNamesFromEntity(AuthorizationEntity $entity)
 {
     $services = array_keys($entity->getArrayCopy());
     array_walk($services, function (&$serviceName) {
         $serviceName = preg_replace('/::.*?$/', '', $serviceName);
     });
     return $services;
 }
 public function testAddingAnRpcServiceWithoutHttpMethodsProvidesDefaults()
 {
     $entity = new AuthorizationEntity();
     $entity->addRpcService('Foo\\V1\\Rpc\\Message\\Controller', 'message');
     $this->assertTrue($entity->has('Foo\\V1\\Rpc\\Message\\Controller::message'));
     $privileges = $entity->get('Foo\\V1\\Rpc\\Message\\Controller::message');
     $this->assertEquals(['GET' => false, 'POST' => false, 'PATCH' => false, 'PUT' => false, 'DELETE' => false], $privileges);
 }