/**
  *
  * @param unknown_type $component
  * @param unknown_type $byClass
  * @throws ComponentException
  * @return \zool\management\ComponentProxy proxy for founded component or null if not found
  */
 public static function getInstance($component, $byClass = false)
 {
     $scopeValue = Scopes::instance()->get($component, null, false);
     if (null !== $scopeValue) {
         return $scopeValue;
     }
     if ($byClass) {
         return self::getComponentByClass($component);
     }
     $component = self::getFullyQualifiedName($component);
     if (null === $component) {
         return null;
         //throw new ComponentException("No component found: $component");
     }
     if (isset(Deployment::instance()->components[$component])) {
         $componentDefinition = Deployment::instance()->components[$component];
         $className = $componentDefinition['class'];
         // instantiate class
         $componentInstance = new $className();
         $proxy = new ComponentProxy($componentInstance, $componentDefinition);
         $scope = self::getComponentScope($component);
         Scopes::instance()->setToScope($scope, $component, $proxy);
         return $proxy;
     }
     if (isset(Deployment::instance()->factories[$component])) {
         return self::getFactory($component);
     }
     return null;
 }
 public function resolveFromContext($name, $default = null)
 {
     $value = $this->getContext($name);
     if (is_null($value)) {
         $value = Scopes::instance()->get($name, $default);
     }
     return is_null($value) ? $default : $value;
 }
 public function run()
 {
     // TODO better method handlin
     $object = Scopes::instance()->get($this->object);
     if ($object != null) {
         if ($object instanceof ZController) {
             $object->beforeAction();
         }
         return call_user_func_array(array($object, $this->method), $this->params);
     } else {
         throw new ZExpressionException($this->object . ' cannot resolved from any context.');
     }
 }
 /**
  *
  * @param Component $component
  * @param array $compoentAnnotations
  * @throws OutjectionException when error happened while outjection property
  */
 public function handle($component, $compoentAnnotations)
 {
     $properties = $compoentAnnotations['properties'];
     foreach ($properties as $property => $propertyDefinition) {
         $annotations = $propertyDefinition['annotations'];
         $outAnnotation = AnnotationManager::instance()->getAnnotation($annotations, self::OUT_ANNOTATION, $this->getTargetReflection($component, $property));
         if (null !== $outAnnotation) {
             $outjectKey = $outAnnotation->value === null ? $property : $outAnnotation->value;
             if ($outAnnotation->required && $component->{$property} === null) {
                 $class = get_class($component);
                 throw new OutjectionException("{$class}::{$property} outjection value is required.");
             }
             Scopes::instance()->setToScope($outAnnotation->scope, $outjectKey, $component->{$property});
         }
     }
 }
 public function __construct($config = array())
 {
     // module name
     parent::__construct('zool', $config);
     $this->config = new Configuration($config);
     // set_error_handler(array($this, 'errorHandler'));
     //set_exception_handler(array($this, 'exceptionHandler'));
     $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
     $reRender = isset($_REQUEST['reRender']) ? $_REQUEST['reRender'] : null;
     $zoolForm = isset($_REQUEST['zoolForm']) ? $_REQUEST['zoolForm'] : null;
     $viewAlias = Request::instance()->getViewId();
     $viewAlias = ($viewAlias == null ? 'app.view/index' : $viewAlias) . '.zool';
     $this->viewProvider = new HtmlViewProvider($viewAlias);
     /**
      * Input value binding
      */
     if ($zoolForm !== null && is_array($zoolForm)) {
         foreach ($zoolForm as $key => $value) {
             list($var, $scope) = explode(':', $key, 2);
             try {
                 if ($scope == UNSPECIFIED_SCOPE) {
                     $scope = EVENT_SCOPE;
                 }
                 Scopes::instance()->setToScope($scope, $var, $value);
             } catch (ZException $e) {
                 throw new ZException($e->getMessage());
             }
         }
     }
     if ($action !== null) {
         $methodExpression = PageScope::instance()->get($action);
         if ($methodExpression instanceof ZMethodExpression) {
             $methodExpression->run();
         }
         // there is no outputing
     }
     EventScope::instance()->reset();
     if ($reRender !== null) {
         $this->viewProvider->handleReRender();
     }
     if ($action !== null || $reRender !== null) {
         die;
     }
 }