コード例 #1
0
ファイル: nReflection.class.php プロジェクト: nyroDev/nyroFwk
	/**
	 * 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');
	}
コード例 #2
0
ファイル: request.class.php プロジェクト: nyroDev/nyroFwk
	/**
	 * 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';
			}
		}
	}