private function __construct() { //$this->reset(); if (!isset($_SESSION[ZOOL_CONTEXT_NAME][self::PREVIOUS_PAGE_NAME])) { $_SESSION[ZOOL_CONTEXT_NAME][self::PREVIOUS_PAGE_NAME] = $this->previousPage = $this->currentPage = Request::instance()->getViewId(); } else { $this->previousPage = $_SESSION[ZOOL_CONTEXT_NAME][self::PREVIOUS_PAGE_NAME]; $this->currentPage = isset($_SESSION[ZOOL_CONTEXT_NAME][self::CURRENT_PAGE_NAME]) ? $_SESSION[ZOOL_CONTEXT_NAME][self::CURRENT_PAGE_NAME] : $this->previousPage; } /* * Persist previous page */ if (!isset($this->currentPage) || $this->currentPage != $this->previousPage) { $this->previousPage = isset($_SESSION[ZOOL_CONTEXT_NAME][self::CURRENT_PAGE_NAME]) ? $_SESSION[ZOOL_CONTEXT_NAME][self::CURRENT_PAGE_NAME] : Request::instance()->getViewId(); $_SESSION[ZOOL_CONTEXT_NAME][self::CURRENT_PAGE_NAME] = $this->currentPage = Request::instance()->getViewId(); $this->reset(); } /* * Reset context, if other page */ if (!isset($_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_NAME]) || $this->currentPage != $this->previousPage) { $this->reset(); } if (isset($_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_CLASSES_NAME])) { $this->classesNeedToLoad = $_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_CLASSES_NAME]; } else { $this->classesNeedToLoad = []; } if (isset($_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_ROOT_PATHS_NAME])) { $this->rootPaths = $_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_ROOT_PATHS_NAME]; } else { $this->rootPaths = []; } foreach ($this->classesNeedToLoad as $class) { Zool::loadClass($class); } foreach ($this->rootPaths as $ns => $path) { Zool::import($path, $ns); } foreach ($_SESSION[ZOOL_CONTEXT_NAME][self::CONTEXT_NAME] as $key => $value) { $this->context[$key] = unserialize($value); } }
/** * * @param array $definitions * @param ReflectionMethod $target * @param array $reflectionParameters * @param array $parameters * @return array */ private function requestParameterized($definitions, $target, $reflectionParameters, $parameters) { $annotation = AnnotationManager::instance()->getAnnotation($definitions['annotations'], self::REQUEST_PARAMETERIZED_ANNOTATION, $target); if (null !== $annotation) { $startIndex = $annotation->required ? 0 : count($parameters); for ($i = $startIndex; $i < count($reflectionParameters); $i++) { $reflectionParameter = $reflectionParameters[$i]; $paramName = $reflectionParameter->getName(); $paramValue = Request::instance()->get($paramName); if ($paramValue === null && $reflectionParameter->isDefaultValueAvailable()) { $paramValue = $reflectionParameter->getDefaultValue(); } elseif ($paramValue === null && !$reflectionParameter->isOptional()) { throw new InjectionException("No request parameter for\r\n {$reflectionParameter->getDeclaringClass()->getName()}::{$reflectionParameter->getDeclaringFunction()->getName()}#{$paramName}"); } $parameters[] = $paramValue; } return $parameters; } }
public function getRequest() { return Request::instance(); }
private function requestParam($component, $property, $annotations, $afterCall) { $reqAnnotation = $this->annotationManager->getAnnotation($annotations, self::REQUEST_PARAM_ANNOTATION, $this->getTargetReflection($component, $property)); if (null !== $reqAnnotation) { if ($afterCall) { $this->setToNull($component, $property); return; } $injectKey = $reqAnnotation->value === null ? $property : $reqAnnotation->value; $injectValue = Request::instance()->get($injectKey); if ($reqAnnotation->required && $injectValue === null) { $class = get_class($component); throw new InjectionException("{class}::{$property} injection value is required."); } $component->{$property} = $injectValue; } }