Exemple #1
0
 /**
  * Attach callback to eventId
  *
  * @param string   $eventId
  * @param callable $callback will be triggered when event triggered
  * @param int      $priority - must be a Priority constant
  */
 public function attachTo($eventId, $callback, $priority = Priority::LOW)
 {
     TypeCheck::doCheck(DataType::STRING, DataType::CALLBACK, Priority::type());
     $queue = $this->queues->get($eventId)->getOrElse(new \SplPriorityQueue());
     /* @var $queue \SplPriorityQueue */
     $queue->insert($callback, $priority);
     if ($queue->count() == 1) {
         $this->queues->set($eventId, $queue);
     }
 }
Exemple #2
0
 /**
  * Sets a new cookie
  *
  * @param CookieInterface $cookie
  *
  * @return $this
  */
 public function addCookie(CookieInterface $cookie)
 {
     $currentCookies = $this->headers->get('Set-Cookie')->getOrElse([]);
     $currentCookies[] = $cookie->__toString();
     $this->headers->set('Set-Cookie', $currentCookies);
     return $this;
 }
 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));
 }
 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']);
     });
 }
Exemple #5
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;
 }
Exemple #6
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;
 }
Exemple #7
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);
     $strat = $this->exclusionStrategy->findStrategy(function ($strategy) {
         return $strategy instanceof GroupsExclusionStrategy;
     });
     if ($strat instanceof GroupsExclusionStrategy) {
         $strat->setGroups((array) $groups);
     } else {
         $this->addExclusionStrategy(new GroupsExclusionStrategy((array) $groups));
     }
     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;
 }
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * Add a path mapping
  *
  * @param string $name
  * @param string $path
  */
 public function addMapping($name, $path)
 {
     $this->paths->set($name, $path);
 }
Exemple #12
0
 /**
  * @param string $eventClass
  */
 private function add(string $eventClass)
 {
     $this->innerMap->set($eventClass::getName(), $eventClass);
 }
Exemple #13
0
 /**
  * Sets a new cookie
  *
  * @param CookieInterface $cookie
  *
  * @return $this
  */
 public function addCookie(CookieInterface $cookie)
 {
     $this->cookies->set($cookie->getName(), $cookie);
 }
Exemple #14
0
 /**
  * Add ResponseOptions
  *
  * @param string $name
  * @param mixed $value
  *
  * @return Request
  */
 public function addResponseOption($name, $value)
 {
     $this->responseOptions->set($name, $value);
     return $this;
 }