Author: David Grudl
Inheritance: extends ReflectionProperty
 /**
  * @param object $object
  * @param string $class
  * @param string $name
  * @param object|object[] $value
  */
 public static function writeProperty($object, $class, $name, $value)
 {
     $rp = new Property($class, $name);
     if (!$rp->isPublic()) {
         $rp->setAccessible(TRUE);
     }
     $rp->setValue($object, $value);
 }
 /**
  * Return an accessible property (setAccessible(true)) or null.
  *
  * @param string $class
  * @param string $property
  * @return \Nette\Reflection\Property
  */
 public function getAccessibleProperty($class, $property)
 {
     try {
         $property = new Reflection\Property($class, $property);
         $property->setAccessible(TRUE);
         return $property;
     } catch (\ReflectionException $e) {
         return NULL;
     }
 }
 /**
  * @internal do not use unless you're absolutely sure what you're doing
  * @return bool|mixed
  */
 public function processMessage()
 {
     if (!($next = $this->nextMessage())) {
         return FALSE;
     }
     list($routingKey, $msgBody) = $next;
     if (!($consumer = $this->findConsumer($routingKey))) {
         throw new InvalidStateException(sprintf('No consumer for exchange "%s" with routing key "%s" found.', $this->exchangeOptions['name'], $routingKey));
     }
     $callbackRefl = new Nette\Reflection\Property($consumer, 'callback');
     $callbackRefl->setAccessible(TRUE);
     $callback = $callbackRefl->getValue($consumer);
     return call_user_func($callback, new AMQPMessage($msgBody, []));
 }
Example #4
0
 private function validateProperty(Property $property, array $ignore)
 {
     if (in_array($property->getDeclaringClass()->getName(), $ignore, TRUE)) {
         return FALSE;
     }
     foreach ($property->getAnnotations() as $name => $value) {
         if (!in_array(Strings::lower($name), ['autowire', 'autowired'], TRUE)) {
             continue;
         }
         if (Strings::lower($name) !== $name || $name !== 'autowire') {
             throw new UnexpectedValueException("Annotation @{$name} on {$property} should be fixed to lowercase @autowire.", $property);
         }
         if ($property->isPrivate()) {
             throw new MemberAccessException("Autowired properties must be protected or public. Please fix visibility of {$property} or remove the @autowire annotation.", $property);
         }
         return TRUE;
     }
     return FALSE;
 }
Example #5
0
 public function __invoke($application, $response)
 {
     if ($response instanceof JsonResponse && ($payload = $response->getPayload()) instanceof \stdClass) {
         if (!$this->forwardHasHappened && isset($payload->redirect)) {
             $url = new Http\UrlScript($payload->redirect);
             $url->setScriptPath($this->httpRequest->url->scriptPath);
             $httpRequest = new Http\Request($url);
             if ($this->router->match($httpRequest) !== NULL) {
                 $prop = new Property($application, 'httpRequest');
                 $prop->setAccessible(TRUE);
                 $prop->setValue($application, $httpRequest);
                 $application->run();
                 exit;
             }
         } elseif ($this->forwardHasHappened && !isset($payload->redirect)) {
             $payload->redirect = $application->getPresenter()->link('this');
         }
     }
 }
 public function __invoke($application, $response)
 {
     if ($response instanceof JsonResponse && ($payload = $response->getPayload()) instanceof \stdClass) {
         if (!$this->forwardHasHappened && isset($payload->redirect)) {
             if (($fragmentPos = strpos($payload->redirect, '#')) !== FALSE) {
                 $this->fragment = substr($payload->redirect, $fragmentPos);
             }
             $url = new Http\UrlScript($payload->redirect);
             $url->setScriptPath($this->httpRequest->url->scriptPath);
             $httpRequest = new Http\Request($url);
             if ($this->router->match($httpRequest) !== NULL) {
                 $prop = new Property('Nette\\Application\\Application', 'httpRequest');
                 $prop->setAccessible(TRUE);
                 $prop->setValue($application, $httpRequest);
                 $application->run();
                 exit;
             }
         } elseif ($this->forwardHasHappened && !isset($payload->redirect)) {
             $payload->redirect = $application->getPresenter()->link('this', $application->getPresenter()->getParameters()) . $this->fragment;
             $this->fragment = '';
         }
     }
 }
Example #7
0
 /**
  * @param \Nette\Reflection\Property
  * @return Builder\Metadata|null
  */
 private function processProperty(\Nette\Reflection\Property $property)
 {
     if (!$property->hasAnnotation('Input')) {
         return;
     }
     $input = $property->getAnnotation('Input');
     $meta = new Builder\Metadata();
     $meta->name = $property->getName();
     $meta->getter = 'get' . ucfirst($meta->name);
     $meta->setter = 'set' . ucfirst($meta->name);
     if ($input instanceof \ArrayObject) {
         $input = (array) $input;
         foreach ($input as $name => $value) {
             switch ($name) {
                 case 'label':
                 case 'type':
                 case 'getter':
                 case 'setter':
                     $meta->{$name} = $value;
                     unset($input[$name]);
                     break;
                 case 'required':
                 case 'minLength':
                 case 'maxLength':
                 case 'min':
                 case 'max':
                     $meta->conditions[$name] = $value;
                     unset($input[$name]);
                     break;
                 default:
                     break;
             }
         }
         $meta->custom = $input;
     }
     return $meta;
 }
Example #8
0
 private function patchService($serviceId, Code\ClassType $advisedClass, Code\PhpNamespace $cg, $constructorInject = FALSE)
 {
     static $publicSetup;
     if ($publicSetup === NULL) {
         $refl = new Nette\Reflection\Property('Nette\\DI\\ServiceDefinition', 'setup');
         $publicSetup = $refl->isPublic();
     }
     $def = $this->getContainerBuilder()->getDefinition($serviceId);
     if ($def->getFactory()) {
         $def->setFactory(new Nette\DI\Statement($cg->getName() . '\\' . $advisedClass->getName()));
     } else {
         $def->setFactory($cg->getName() . '\\' . $advisedClass->getName());
     }
     if (!$constructorInject) {
         $statement = new Nette\DI\Statement(AdvisedClassType::CG_INJECT_METHOD, ['@Nette\\DI\\Container']);
         if ($publicSetup) {
             array_unshift($def->setup, $statement);
         } else {
             $setup = $def->getSetup();
             array_unshift($setup, $statement);
             $def->setSetup($setup);
         }
     }
 }
Example #9
0
	/**
	 * @param \Nette\Reflection\Property
	 * @param mixed
	 * @return mixed
	 */
	private function getValue(\Nette\Reflection\Property $reflection, $input)
	{
		$reflection->setAccessible(TRUE);
		return $reflection->getValue($input);
	}
Example #10
0
 private function getClassMap()
 {
     if ($this->registeredClasses !== NULL) {
         return $this->registeredClasses;
     }
     if (property_exists('Nette\\DI\\Container', 'classes')) {
         return $this->registeredClasses = $this->sl->classes;
     }
     $refl = new Nette\Reflection\Property('Nette\\DI\\Container', 'meta');
     $refl->setAccessible(TRUE);
     $meta = $refl->getValue($this->sl);
     $this->registeredClasses = array();
     foreach ($meta['types'] as $type => $serviceIds) {
         if (isset($this->registeredClasses[$type])) {
             $this->registeredClasses[$type] = FALSE;
             continue;
         }
         $this->registeredClasses[$type] = $serviceIds;
     }
     return $this->registeredClasses;
 }
Example #11
0
 /**
  * @param string $param
  * @return array
  */
 public static function getAnnotations($class, $param)
 {
     $parameter = new Nette\Reflection\Property($class, $param);
     return $parameter->getAnnotations();
 }