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
 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.º 3
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.º 4
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.º 5
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;
 }