Exemplo n.º 1
0
	/**
	 * Call a method from an object. Used when the function name is dynamic
	 *
	 * @param object $object The object where call the function
	 * @param string $function Function name
	 * @param array $args Argumens for the call
	 * @return mixed Function result
	 * @throws nExecption If method is not callable
	 */
	public static function callMethod($object, $function, $args=array()) {
		$ref = new nReflection($object);
		if ($ref->hasMethod($function)
			&& ($meth = $ref->getMethod($function))
			&& $meth->isPublic()) {
				if (!is_array($args)) {
					if (!empty($args))
						$args = array($args);
					else
						$args = array();
				}
				return $meth->invokeArgs($object, $args);
			}
		throw new nException('Method not callable');
	}
Exemplo n.º 2
0
	/**
	 * Init the module requested
	 */
	private static function initModule() {
		if (!self::$module) {
			self::$module = factory::getModule(self::$uriInfo['module'], array(), self::$scaffold, self::$cfg->allowScaffold);
			if (self::$module instanceof module_scaffold_controller && !self::$cfg->allowScaffold) {
				// Need to test if the action was expressly defined
				$ref = new nReflection();
				$className = 'module_'.self::$uriInfo['module'].'_controller';

				$prefix = null;
				$action = self::$uriInfo['action'];
				if (array_key_exists(NYROENV, self::$module->getCfg()->basicPrefixExec) &&
						in_array($action, self::$module->getCfg()->getInArray('basicPrefixExec', NYROENV)))
					$prefix = ucfirst(NYROENV);
				else if (self::$module->getCfg()->prefixExec && !in_array($action, self::$module->getCfg()->noPrefixExec))
					$prefix = self::$module->getCfg()->prefixExec;

				$exec = 'exec'.$prefix.ucFirst($action);
				if ($ref->rebuild($className)) {
					if ($ref->getMethod($exec)->getDeclaringClass()->name != $className)
						throw new module_exception('Request - initModule: '.self::$uriInfo['module'].'.'.$exec.' not found.');
				}
			}
			if (self::$scaffold) {
				self::$uriInfo['moduleScaffold'] = self::$uriInfo['module'];
				self::$uriInfo['module'] = 'scaffold';
			}
		}
	}
Exemplo n.º 3
0
	protected function afterInit() {
		$t = factory::get('tpl');
		$this->module = factory::getModule(request::get('module'));
		nReflection::callMethod($this->module, request::get('action').'Action', request::get('param'));
	}
Exemplo n.º 4
0
 /**
  * Get a new object, with loading its definition and configuration
  *
  * @param string $className The classname to create
  * @param array $cfg The config
  * @return object The new object
  */
 public static function get($className, array $cfg = array())
 {
     if (self::$cfg && ($tmp = self::$cfg->getInArray('classAlias', $className))) {
         $className = $tmp;
     }
     self::load($className);
     $ref = new nReflection();
     if ($ref->rebuild($className)) {
         $prm = self::loadCfg($className);
         self::mergeCfg($prm, $cfg);
         $inst = $ref->newInstanceCfg(new config($prm));
         return $inst;
     } else {
         throw new nException('Factory - load: Unable to bluid ' . $className . '.');
     }
 }