Exemplo n.º 1
0
 /**
  * @param Parameter $parameter
  * @param Map $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     foreach ($this->getTypes($parameter) as $i => $type) {
         if ($serialized->has("multi-{$i}")) {
             $optionParameter = new Parameter($parameter->getName(), $type);
             return $this->getField($optionParameter)->inflate($optionParameter, $serialized["multi-{$i}"]);
         }
     }
     return null;
 }
Exemplo n.º 2
0
 protected function determineHeaders($server)
 {
     $headers = new Map();
     foreach (self::$headerKeys as $headerKey => $serverKey) {
         if (array_key_exists($serverKey, $server)) {
             $headers->set($headerKey, $server[$serverKey]);
         }
     }
     return $headers;
 }
Exemplo n.º 3
0
 private function getHeaders()
 {
     $headers = new Map();
     foreach (self::$headers as $header) {
         if ($this->environment->getHeaders()->has($header)) {
             $headers->set($header, $this->environment->getHeaders()->get($header));
         }
     }
     return $headers;
 }
Exemplo n.º 4
0
 private function accumulate(Map $acc, BaseProperty $property)
 {
     if (!$acc->has($property->name())) {
         $acc->set($property->name(), $property);
     } else {
         $multi = $acc->get($property->name());
         if (!$multi instanceof property\MultiProperty) {
             $multi = new property\MultiProperty($this->factory, $property);
             $multi->add($acc->get($property->name()));
             $acc->set($property->name(), $multi);
         }
         $multi->add($property);
     }
 }
Exemplo n.º 5
0
 /**
  * @param Set $keys
  * @return Map with only the given keys
  */
 public function select(Set $keys)
 {
     $selection = new Map();
     foreach ($keys as $key) {
         if ($this->has($key)) {
             $selection->set($key, $this->get($key));
         }
     }
     return $selection;
 }
Exemplo n.º 6
0
 /**
  * @param Parameter $parameter
  * @param \watoki\collections\Map $serialized
  * @return object
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $reader = new PropertyReader($this->types, $this->getClass($parameter));
     $properties = [];
     foreach ($reader->readInterface() as $property) {
         if ($serialized->has($property->name())) {
             $param = $this->makePropertyParameter($parameter, $property);
             $properties[$property->name()] = $this->getField($param)->inflate($param, $serialized[$property->name()]);
         }
     }
     $injector = new Injector(new Factory());
     $instance = $injector->injectConstructor($this->getClass($parameter), $properties, function () {
         return false;
     });
     foreach ($reader->readInterface() as $property) {
         if ($property->canSet()) {
             $property->set($instance, $properties[$property->name()]);
         }
     }
     return $instance;
 }
Exemplo n.º 7
0
 private function getCaughtEventsCount($listener, $event)
 {
     $count = 0;
     if ($this->caught->has($listener)) {
         foreach ($this->caught->get($listener) as $caughtEvent) {
             if (get_class($caughtEvent) == $event) {
                 $count++;
             }
         }
     }
     return $count;
 }
Exemplo n.º 8
0
 /**
  * Intercepts all reading property accesses and return corresponding Mockster instance
  *
  * @param string $name
  * @return Mockster
  * @throws \ReflectionException
  */
 public function __get($name)
 {
     if (!array_key_exists($name, $this->propertyMocksters)) {
         if (!$this->properties->has($name)) {
             throw new \ReflectionException("The property [{$this->class}::{$name}] does not exist");
         }
         if ($this->uuts) {
             $mockster = $this->properties[$name]->get($this->uuts[0])->__mockster;
         } else {
             $mockster = new Mockster($this->getTypeHint($name), $this->factory);
         }
         $this->propertyMocksters[$name] = $mockster;
     }
     return $this->propertyMocksters[$name];
 }
Exemplo n.º 9
0
 private function thenThePropertiesShouldBe($array)
 {
     $this->assertEquals($array, $this->properties->keys()->toArray());
 }
Exemplo n.º 10
0
 protected function wrapUrl(Element $element, $target)
 {
     $target = Url::fromString($target);
     $box = $this->name;
     if ($element->getAttribute('target')) {
         $box = $element->getAttribute('target')->getValue();
         if (substr($box, 0, 7) == '_parent') {
             $remaining = substr($element->getAttribute('target')->getValue(), strlen('_parent'));
             $element->setAttribute('target', $remaining);
             if (!$remaining) {
                 $element->getAttributes()->removeElement($element->getAttribute('target'));
             }
             return $target;
         } else {
             if (substr($box, 0, 1) == '_') {
                 return $target;
             }
         }
         $element->getAttributes()->removeElement($element->getAttribute('target'));
     }
     $wrapped = Url::fromString('');
     $wrapped->setFragment($target->getFragment());
     $params = new Map();
     if ($box === $this->exception) {
         $wrapped->setPath($target->getPath());
         if ($wrapped->getPath()->isEmpty()) {
             $wrapped->setPath($this->path);
         }
         foreach ($target->getParameters() as $key => $value) {
             if (substr($key, 0, strlen(self::$PREFIX)) == self::$PREFIX) {
                 $params->set($key, $value);
             } else {
                 $wrapped->getParameters()->set($key, $value);
             }
         }
     } else {
         if ($target->getPath()->toString()) {
             $params->set(Box::$TARGET_KEY, $target->getPath()->toString());
         }
         $params->merge($target->getParameters());
     }
     foreach ($this->state as $name => $state) {
         if ($name !== self::$PREFIX . $box) {
             $wrapped->getParameters()->set($name, $state);
         }
     }
     if ($box !== $this->exception) {
         $wrapped->getParameters()->set(self::$PREFIX . $box, $params);
         $wrapped->getParameters()->set(Box::$PRIMARY_TARGET_KEY, $box);
     } else {
         if ($wrapped->getParameters()->has(Box::$PRIMARY_TARGET_KEY)) {
             if (!$params->isEmpty()) {
                 $wrapped->getParameters()->set(self::$PREFIX . $box, $params);
             }
             if ($wrapped->getParameters()->has(Box::$PRIMARY_TARGET_KEY)) {
                 $wrapped->getParameters()->remove(Box::$PRIMARY_TARGET_KEY);
             }
             if ($wrapped->getParameters()->has(Box::$TARGET_KEY)) {
                 $wrapped->getParameters()->remove(Box::$TARGET_KEY);
             }
         }
     }
     return $wrapped;
 }
Exemplo n.º 11
0
 protected function updateBreadcrumb($crumbs, $object, Map $args)
 {
     if ($crumbs) {
         $newCrumbs = [];
         foreach ($crumbs as $crumb) {
             /** @noinspection PhpUnusedLocalVariableInspection */
             list($label, $crumbAction, $crumbArgs) = $crumb;
             if (get_class($object) == $crumbAction && $args->toArray() == $crumbArgs) {
                 break;
             }
             $newCrumbs[] = $crumb;
         }
         $crumbs = $newCrumbs;
     }
     $representer = $this->registry->getActionRepresenter($object);
     $caption = $representer->toString($object);
     $crumbs[] = [$caption, $representer->getClass(), $args->toArray()];
     $this->saveBreadCrumbs($crumbs);
     return $crumbs;
 }
Exemplo n.º 12
0
 /**
  * @param ActionPanel $value
  * @return mixed
  */
 public function render($value)
 {
     $heading = $this->actions->getAction($value->getActionId())->caption();
     return (string) (new Panel($heading, $this->getContent($value)))->setMaxHeight($value->getMaxHeight())->setRightHeading([new Element('a', ['href' => $this->baseUrl->appended($value->getActionId())->withParameters(Map::toCollections($value->getParameters()))], [new Element('span', ['class' => 'glyphicon glyphicon-circle-arrow-right'])])])->render($this->renderers);
 }
Exemplo n.º 13
0
 public function selectProperties($names)
 {
     $this->properties = $this->properties->select(new Set($names));
     return $this;
 }
Exemplo n.º 14
0
 /**
  * @return WebRequest
  */
 protected function copy()
 {
     return new WebRequest($this->getContext(), $this->getTarget(), $this->getMethod(), $this->getArguments()->copy(), $this->formats->copy(), $this->headers->copy());
 }
Exemplo n.º 15
0
 public function toString()
 {
     return json_encode(array('context' => $this->context->toString(), 'target' => $this->target->toString(), 'method' => $this->method, 'arguments' => $this->arguments->toArray()));
 }
Exemplo n.º 16
0
Arquivo: Url.php Projeto: watoki/curir
 /**
  * @return static
  */
 protected function copy()
 {
     return new Url($this->scheme, $this->host, $this->port, new Path($this->elements), $this->parameters->deepCopy(), $this->fragment);
 }