Exemple #1
0
	/**
	 * [getModelClassAnnotations description]
	 * @return [type]
	 */
	public function getModelClassAnnotations(){
	    $model = new ReflectionClass($this->model);
	    $this->modelAnotations['model'] = rifAnotations::getAnnotations($model->getDocComment());
	    $properties   = $model->getProperties();
	    $anotations = array();
		foreach ($properties as $property) {
			$anotations[$property->getName()] = rifAnotations::getAnnotations($property->getDocComment());
		}
		$this->modelAnotations['properties'] = $anotations;
	}
Exemple #2
0
 public function execute($argv)
 {
     if (php_sapi_name() == 'cli') {
         $shellCommand = $argv[1];
         $reflectionShell = new ReflectionClass($shellCommand);
         $shellAnotations = rifAnotations::getAnnotations($reflectionShell->getDocComment());
         $shell = new $shellCommand();
         $shell->lng = $this->lng;
         unset($argv[0]);
         unset($argv[1]);
         $argv = array_values($argv);
         if (is_array($shellAnotations) && count($shellAnotations)) {
             if (!is_array($shellAnotations['param'])) {
                 $shellParam = explode(" ", $shellAnotations["param"]);
                 if (isset($argv[$shellParam[0]])) {
                     $shell->{$shellParam}[1] = $argv[$shellParam[0]];
                 }
             } else {
                 foreach ($shellAnotations['param'] as $shellParam) {
                     $shellParam = explode(" ", $shellParam);
                     if (isset($argv[$shellParam[0]])) {
                         $shell->{$shellParam}[1] = $argv[$shellParam[0]];
                     }
                 }
             }
         }
         $rifModel = "rifModel";
         if (isset($shell->models) && is_array($shell->models)) {
             foreach ($shell->models as $model) {
                 $shell->{$model} = new $rifModel($this->rifCore->core['config'], new $model());
             }
         }
         if (isset($shell->components) && is_array($shell->components)) {
             foreach ($shell->components as $component) {
                 $shell->{$component} = new $component();
             }
         }
         $shell->run($this->rifCore);
     } else {
         rifException::callableException(array('message' => $this->lng->__("Incorrect command execution")));
     }
 }
	/**
	 * [getMethodParameters Gets the method parameters using the ReflectionClass]
	 * @return array
	 */
	private function getMethodParameters(rifRouting $rifRouting){
		$controller = $rifRouting->route['controller'];
		$action = $rifRouting->route['action'];
		$class = new ReflectionClass($controller);
		$method = $class->getMethod($action);
		$required_params = array();
		$methodAnotations = rifAnotations::getAnnotations($class->getMethod($action)->getDocComment());
		if(isset($methodAnotations['required'])){
			if(is_array($methodAnotations['required'])){
				foreach($methodAnotations['required'] as $var){
					$required_params[] = $var;
				}
			}else{
				$required_params[] = $methodAnotations['required'];
			}
		}
		$parameters = $method->getParameters();
		$params_new = array();
		$params_old = $rifRouting->route['vars'];
		for($i = 0; $i<count($parameters);$i++){
			$key = $parameters[$i]->getName();
			$headerKey = "HTTP_".strtoupper($key);
			if(array_key_exists($key,$params_old)){
				$params_new[$i] = $params_old[$key];
			}else if(array_key_exists($headerKey, $_SERVER)){
				$params_new[$i] = $_SERVER["HTTP_".strtoupper($key)];
			}else{
				if(in_array($key, $required_params)){
					rifException::instanceException(array(
						'message' => $this->lng->__("The method __action__ (__controller__) has  a required parameter __key__ that is not defined",array(
							'controller' => $controller,
							'action' => $action,
							'key' => $key
						))
					));
				}
			}
		}
		return $params_new;
	}