Ejemplo n.º 1
0
 public function testAddMap()
 {
     $map = new Map();
     $map->set('foo', array('bar'));
     $this->map->addMap($map);
     $this->assertEquals(array('foo' => array('bar'), 'bar' => 'baz', 'baz' => 'boo'), iterator_to_array($this->map));
 }
Ejemplo n.º 2
0
 /**
  * @param string $name
  * @return string
  * @throws \OutOfBoundsException
  */
 public function getClassByEventName(string $name)
 {
     if (!$this->innerMap->containsKey($name)) {
         throw new \OutOfBoundsException("Event class not mapped: '{$name}'.");
     }
     return $this->innerMap->get($name)->get();
 }
Ejemplo n.º 3
0
 public function register(Application $app)
 {
     $app['satis'] = $app->share(function () use($app) {
         $filesystem = new Filesystem();
         $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) {
             $registry->registerHandler('serialization', 'RepositoryCollection', 'json', function ($visitor, Map $map, array $type, Context $context) {
                 // We change the base type, and pass through possible parameters.
                 $type['name'] = 'array';
                 $data = $map->values();
                 return $visitor->visitArray($data, $type, $context);
             });
         })->configureHandlers(function (HandlerRegistry $registry) {
             $registry->registerHandler('deserialization', 'RepositoryCollection', 'json', function ($visitor, array $data, array $type, Context $context) {
                 // We change the base type, and pass through possible parameters.
                 $type['name'] = 'array';
                 $objects = $visitor->visitArray($data, $type, $context);
                 $map = new Map();
                 foreach ($objects as $object) {
                     $map->set($object->getId(), $object);
                 }
                 return $map;
             });
         })->build();
         $filePersister = new FilePersister($filesystem, $app['satis.filename'], $app['satis.auditlog']);
         $jsonPersister = new JsonPersister($filePersister, $serializer, $app['satis.class']);
         return new Manager($jsonPersister);
     });
     $app['satis.lock'] = $app->share(function () use($app) {
         return new LockProcessor($app['satis']);
     });
 }
Ejemplo n.º 4
0
 /**
  * Translate view path
  *
  * @param string $identifier
  *
  * @return string
  *
  * @throws InvalidArgumentException
  */
 public function translate($identifier)
 {
     $parts = explode(':', $identifier, 2);
     if (count($parts) == 2) {
         $basePath = $this->paths->get($parts[0])->getOrThrow(new InvalidArgumentException('Invalid application name for view identifier: ' . $identifier));
         if (!file_exists($basePath . DIRECTORY_SEPARATOR . $parts[1])) {
             throw new InvalidArgumentException('Invalid view name');
         }
         return $basePath . DIRECTORY_SEPARATOR . $parts[1];
     } else {
         throw new InvalidArgumentException('Invalid view name provided');
     }
 }
Ejemplo n.º 5
0
 public function getIterator()
 {
     foreach ($this->serviceIds as $k => $id) {
         $this->set($k, $this->container->get($this->serviceIds[$id]));
         unset($this->serviceIds[$k]);
     }
     return parent::getIterator();
 }
Ejemplo n.º 6
0
 /**
  * @param array|string $groups
  */
 public function setGroups($groups)
 {
     if (empty($groups)) {
         throw new \LogicException('The groups must not be empty.');
     }
     $this->attributes->set('groups', (array) $groups);
     $this->addExclusionStrategy(new GroupsExclusionStrategy((array) $groups));
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Appends an element at the end of the sequence.
  * @param string $key
  * @param T $value
  * @return self
  */
 public function set($key, $value)
 {
     if ($value instanceof $this->_type) {
         parent::set($key, $value);
     } else {
         throw new \UnexpectedValueException("TypedMap<{$this->_type}> can only hold objects of {$this->_type} class.");
     }
     return $this;
 }
 /**
  * @param \Zend\ServiceManager\ServiceLocatorInterface $sl
  * @param array                                        $array
  *
  * @return \PhpCollection\Map
  * @throws \InvalidArgumentException
  */
 private function buildMap(ServiceLocatorInterface $sl, array $array)
 {
     $map = new Map();
     foreach ($array as $format => $visitorName) {
         $visitor = $visitorName;
         if (is_string($visitorName)) {
             if ($sl->has($visitorName)) {
                 $visitor = $sl->get($visitorName);
             } elseif (class_exists($visitorName)) {
                 $visitor = new $visitorName();
             }
         }
         if ($visitor instanceof VisitorInterface) {
             $map->set($format, $visitor);
             continue;
         }
         throw new InvalidArgumentException(sprintf('Invalid (de-)serialization visitor"%s" given, must be a service name, ' . 'class name or an instance implementing JMS\\Serializer\\VisitorInterface', is_object($visitorName) ? get_class($visitorName) : (is_string($visitorName) ? $visitorName : gettype($visitor))));
     }
     return $map;
 }
Ejemplo n.º 9
0
 /**
  * Trigger event.
  *
  * @param AbstractEvent $event
  */
 public function trigger(AbstractEvent $event)
 {
     $queue = clone $this->queues->get($event->getEventId())->getOrElse(new \SplPriorityQueue());
     /* @var $queue \SplPriorityQueue */
     while ($queue->valid()) {
         $callback = $queue->extract();
         call_user_func_array($callback, ['event' => $event]);
         if (is_array($callback)) {
             $subscriber = get_class($callback[0]) . '::' . $callback[1];
         } elseif (is_string($callback)) {
             $subscriber = $callback;
         } else {
             $subscriber = get_class($callback);
         }
         $this->logger->debug("Event '" . $event->getEventId() . "' triggered '" . $subscriber . "'");
         if (!$event->shouldPropagate()) {
             $this->logger->debug("'{$subscriber}' stopped propagation of '" . $event->getEventId() . "'");
             break;
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Set the value of a map element, regardless of if the key already exists
  *
  * @param string $key
  * @param mixed  $value
  */
 public function set($key, $value)
 {
     $this->map->set($key, $value);
 }
Ejemplo n.º 11
0
 /**
  * Process application metadata
  *
  * @param Map $metadata
  */
 public function processMetadata(Map &$metadata)
 {
     $metadata->set($this->getApplicationName(), $appMetadata = new Map($this->metaData()));
     $appMetadata->set('application_name', $this->getApplicationName());
     $appMetadata->set('application_path', $this->getApplicationPath());
     $appMetadata->set('application_namespace', $this->getNamespace());
     $appMetadata->set('application_version', $this->getVersion());
     foreach ($this->getParentApplications() as $app) {
         $app->processMetadata($metadata);
     }
 }
Ejemplo n.º 12
0
 /**
  * @return array
  */
 public function getGroups()
 {
     return $this->attributes->get('groups');
 }
Ejemplo n.º 13
0
 /**
  * Get response cookies
  *
  * @return Map
  */
 public function getCookies()
 {
     return $this->headers->get('Set-Cookie')->getOrElse([]);
 }
Ejemplo n.º 14
0
 /**
  * Sets a new cookie
  *
  * @param CookieInterface $cookie
  *
  * @return $this
  */
 public function addCookie(CookieInterface $cookie)
 {
     $this->cookies->set($cookie->getName(), $cookie);
 }
Ejemplo n.º 15
0
 protected function setUp()
 {
     $this->map = new Map();
     $this->map->setAll(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'boo'));
 }
Ejemplo n.º 16
0
 /**
  * Get Response Option
  *
  * @param string $name
  *
  * @return Some|None
  */
 public function getResponseOption($name)
 {
     return $this->responseOptions->get($name);
 }