Esempio n. 1
0
 /**
  * Class Constructor. 
  */
 public function __construct()
 {
     // 			$this->config		=Nutshell::getInstance()->config;
     // 			$this->core			=Nutshell::getInstance();
     // 			$this->plugin		=Nutshell::getInstance()->plugin;
     // 			$this->request		=Nutshell::getInstance()->request;
     HookManager::execute('core\\plugin', ObjectHelper::getBaseClassName($this) . 'OnConstruct');
 }
Esempio n. 2
0
 public static function registerBehaviours()
 {
     static::registerBehaviour(get_called_class(), 'NamedSession', function ($classInstance) {
         $session = Nutshell::getInstance()->plugin->Session;
         if (!isset($session->{ObjectHelper::getBaseClassName($classInstance)})) {
             $session->{ObjectHelper::getBaseClassName($classInstance)} = new stdClass();
         }
         $classInstance->session = $session->{ObjectHelper::getBaseClassName($classInstance)};
     });
 }
Esempio n. 3
0
 public function buildDescriptor()
 {
     $descriptor = array();
     foreach ($this->config->{$this->ref}->providers as $providerName => $provider) {
         if ($provider->type == 'polling') {
             $thisProvider = array('type' => $provider->type, 'url' => $this->plugin->Url->makeURL(strtolower(ObjectHelper::getBaseClassName($this->controller)) . '/' . $providerName), 'interval' => isset($provider->interval) ? $provider->interval : self::DEFAULT_INTERVAL);
         } else {
             if ($provider->type == 'remoting') {
                 $thisProvider = array('type' => $provider->type, 'url' => $this->plugin->Url->makeURL(strtolower(ObjectHelper::getBaseClassName($this->controller)) . '/' . $providerName), 'namespace' => $this->nsPrefix . '.' . $providerName, 'actions' => array());
                 foreach ($provider->modules as $moduleName => $module) {
                     for ($i = 0, $j = count($module); $i < $j; $i++) {
                         $thisProvider['actions'][$moduleName][] = array('name' => $module[$i]->name, 'len' => $module[$i]->args);
                     }
                 }
             } else {
                 throw new DirectException(DirectException::INVALID_PROVIDER_TYPE, $provider->type);
             }
         }
         $descriptor[] = $thisProvider;
     }
     header('Content-type:application/json;');
     print json_encode($descriptor);
 }
Esempio n. 4
0
 public static function autoload($className)
 {
     $namespace = ObjectHelper::getNamespace($className);
     $className = ObjectHelper::getBaseClassName($className);
     //Check for an application plugin's library class.
     // if (strstr($namespace,'plugin\\'))
     // {
     // 	$namespaceParts	=explode('\\',$namespace);
     // 	$where			=array_shift($namespaceParts);
     // 	$filePath		=false;
     // 	if ($where==='nutshell')
     // 	{
     // 		$filePath=NS_HOME.implode(_DS_,$namespaceParts)._DS_.$className.'.php';
     // 	}
     // 	else if ($where==='application')
     // 	{
     // 		$filePath=APP_HOME.implode(_DS_,$namespaceParts)._DS_.$className.'.php';
     // 	}
     // 	if (is_file($filePath))
     // 	{
     // 		//Invoke the plugin.
     // 		require_once($filePath);
     // 	}
     // 	else
     // 	{
     // 		throw new ('Unable to autoload class "'.$namespace.'\\'.$className.'".');
     // 	}
     // }
     // //Check for a plugin behaviour.
     // else
     if (strstr($namespace, 'behaviour\\')) {
         list(, , $plugin) = explode('\\', $namespace);
         $pathSuffix = 'plugin' . _DS_ . $plugin . _DS_ . 'behaviour' . _DS_ . $className . '.php';
         if (is_file($file = NS_HOME . $pathSuffix)) {
             //Invoke the plugin.
             Nutshell::getInstance()->plugin->{ucfirst($plugin)};
         } else {
             if (is_file($file = APP_HOME . $pathSuffix)) {
                 Nutshell::getInstance()->plugin->{ucfirst($plugin)};
             } else {
                 throw new LoaderException(LoaderException::CANNOT_AUTOLOAD_CLASS, 'Unable to autoload class "' . $namespace . $className . '".');
             }
         }
     } else {
         $namespaceParts = explode('\\', $namespace);
         $where = array_shift($namespaceParts);
         $filePath = false;
         if ($where === 'nutshell') {
             $filePath = NS_HOME . implode(_DS_, $namespaceParts) . _DS_ . $className . '.php';
         } else {
             if ($where === 'application') {
                 $filePath = APP_HOME . implode(_DS_, $namespaceParts) . _DS_ . $className . '.php';
             }
         }
         if (is_file($filePath)) {
             //Invoke the plugin.
             require $filePath;
         } else {
             throw new LoaderException(LoaderException::CANNOT_AUTOLOAD_CLASS, 'Unable to autoload class "' . $namespace . '\\' . $className . '"', '"' . $filePath . '" does not exist');
         }
     }
 }
Esempio n. 5
0
 /**
  * Register's a custom behavior with attached functionality.
  * 
  * You would usually attach a closure to this method as the callback and embed
  * functionality which performs the specific "behaviour".
  * 
  * The closure must accept a single parameter "$classInstance" which is the instance
  * of the class which has implemented the custom behaviour.
  * 
  * @access protected
  * @static
  * @param Mixed $plugin - Either the plugin name or an instance of the plugin.
  * @param String $behaviourName - The name of the behaviour to register.
  * @param Mixed $callback - A function reference or Closure.
  * @return Void
  * @throws Exception
  */
 protected static function registerBehaviour($plugin, $behaviourName, $callback)
 {
     $pluginName = lcfirst(ObjectHelper::getBaseClassName($plugin));
     $behaviour = 'nutshell\\behaviour\\' . $pluginName . '\\' . $behaviourName;
     if (!isset(self::$behaviours[$behaviour])) {
         self::$behaviours[$behaviour] = $callback;
     } else {
         throw new Exception('Plugin ".$pluginName." tried to define the behaviour "' . $behaviourName . '". But this behaviour has already been defined.');
     }
 }
Esempio n. 6
0
 public function __construct()
 {
     parent::__construct();
     $this->config = Nutshell::getInstance()->config->plugin->{ObjectHelper::getBaseClassName($this->getParentPlugin())};
 }