Example #1
0
 protected function parseOptions($options)
 {
     if (xo_has(self::SCOPE_CONFIGS, $options) && xo_get(self::SCOPE_CONFIGS, $options)) {
         $scopeConfigs = xo_get(self::SCOPE_CONFIGS);
         $scopes = array();
         foreach ($scopeConfigs as $scopeConfig) {
             $scopeConfig[XIDE_Scope::RELATIVE_REGISTRY_NAMESPACE] = xo_get(self::SCOPE_NS_PREFIX) . '.' . $scopeConfig[XIDE_Scope::SCOPE_NAME] . '.absolute';
             $scopeConfig[XIDE_Scope::ABSOLUTE_REGISTRY_NAMESPACE] = xo_get(self::SCOPE_NS_PREFIX) . '.' . $scopeConfig[XIDE_Scope::SCOPE_NAME] . '.relative';
             $scopes[] = new XIDE_Scope($scopeConfig);
         }
         xo_set(self::SCOPES, $scopes);
     }
 }
Example #2
0
 protected function parseOptions($options)
 {
     /***
      * Register relative scope variables
      */
     if (xo_has(self::RELATIVE_VARIABLES, $options) && xo_get(self::RELATIVE_VARIABLES, $options)) {
         $variables = xo_get(self::RELATIVE_VARIABLES, $options);
         foreach ($variables as $variable => $value) {
             $this->registerRelative($variable, $value);
         }
     }
     /***
      * Register absolute scope variables
      */
     if (xo_has(self::ABSOLUTE_VARIABLES, $options) && xo_get(self::ABSOLUTE_VARIABLES, $options)) {
         $variables = xo_get(self::ABSOLUTE_VARIABLES, $options);
         foreach ($variables as $variable => $value) {
             $this->registerAbsolute($variable, $value);
         }
     }
 }
Example #3
0
 public function initStore($force = false)
 {
     //skip
     if ($force === false && $this->_store) {
         return true;
     }
     //Try with store data first
     if (xo_has(self::STORE_DATA) && is_object(xo_get(self::STORE_DATA))) {
         $this->initWithData(xo_get(self::STORE_DATA));
         return true;
     }
     //No store data provided from outside, use the store class
     if (xo_has(self::STORE_CLASS) && xo_get(self::STORE_CLASS)) {
         $_storeClz = xo_get(self::STORE_CLASS);
         //check its an instance already :
         if (is_object($_storeClz)) {
             $this->_store = $_storeClz;
             return true;
         } elseif (is_string($_storeClz) && class_exists($_storeClz)) {
             $_ctrArgs = xo_has(self::STORE_CONF) ? xo_get(self::STORE_CONF) : array();
             $this->_store = new $_storeClz($_ctrArgs);
             return true;
         }
     }
     return false;
 }
Example #4
0
 public function _onItem($evt)
 {
     if ($this->_vfs !== null && is_array($evt) && array_key_exists('item', $evt)) {
         $item = $evt['item'];
         //clean meta data
         //pick ori name as path and swap with path!
         $item->{XAPP_NODE_FIELD_PATH} = '' . $item->{XAPP_NODE_FIELD_NAME};
         //track path
         $path = '' . $item->{XAPP_NODE_FIELD_NAME};
         //clean up file name
         $fileName = '' . $path;
         if (xo_has(self::FILE_NAME_CLEAN_PATTERN) && xo_get(self::FILE_NAME_CLEAN_PATTERN)) {
             $fileName = preg_replace(xo_get(self::FILE_NAME_CLEAN_PATTERN), '', $fileName);
         }
         $fileName = pathinfo($fileName, PATHINFO_FILENAME);
         //swap
         $item->{XAPP_NODE_FIELD_NAME} = $fileName;
         //file
         if ($item->{XAPP_NODE_FIELD_IS_DIRECTORY} === false) {
             $item->type = 'node';
             $this->_currentNodes['items'][] = $item;
             //dir
         } else {
             if ($item->{XAPP_NODE_FIELD_IS_DIRECTORY} === true) {
                 //tree specific
                 if (strpos($item->{XAPP_NODE_FIELD_PATH}, '/') !== false) {
                     $item->type = 'node';
                 } else {
                     $item->type = 'leaf';
                     $item->parentId = '';
                 }
                 //prepare directory scan options
                 $directoryOptions = array(XApp_Directory_Utils::OPTION_ONLY_FILES => false, XApp_Directory_Utils::OPTION_ONLY_DIRS => false, XApp_Directory_Utils::OPTION_RECURSIVE => false, XApp_Directory_Utils::OPTION_CLEAR_PATH => true);
                 //enumerate
                 $childList = $this->_vfs->ls('root/' . $item->{XAPP_NODE_FIELD_PATH} . '/', true, array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_ISDIR, XApp_File_Utils::OPTION_DIR_LIST => $directoryOptions, XApp_File_Utils::OPTION_EMIT => false));
                 //store child references in item
                 if ($childList && count($childList)) {
                     //prepare array
                     if (!xapp_property_exists($item, XAPP_NODE_FIELD_CHILDREN)) {
                         $item->{XAPP_NODE_FIELD_CHILDREN} = array();
                     }
                     foreach ($childList as $child) {
                         //build item unique reference key
                         $key = $item->{XAPP_NODE_FIELD_PATH} . '/' . $child->name;
                         array_push($item->{XAPP_NODE_FIELD_CHILDREN}, array('_reference' => $key));
                         //$child->parentId = $item->{XAPP_NODE_FIELD_PATH};
                     }
                 } else {
                     if (xo_get(self::SHOW_EMPTY_FOLDERS) === false) {
                         //return null;
                     } else {
                         $item->{XAPP_NODE_FIELD_CHILDREN} = array();
                     }
                 }
                 //add to our flat! list
                 $this->_currentNodes['items'][] = $item;
             }
         }
         return $item;
     }
 }
Example #5
0
 private function parseOptions($options)
 {
     if ($this->_object == null && $options && xo_has(self::MANAGED_CLASS, $options)) {
         //the class
         $_managedClass = xo_get(self::MANAGED_CLASS, $options);
         //check its an instance already :
         if (is_object($_managedClass)) {
             $this->_object = $_managedClass;
         } elseif (is_string($_managedClass) && class_exists($_managedClass)) {
             $baseClasses = xo_has(self::MANAGED_CLASS_BASE_CLASSES, $options) ? xo_get(self::MANAGED_CLASS_BASE_CLASSES, $options) : null;
             $_ctrArgs = xo_has(self::MANAGED_CLASS_OPTIONS, $options) ? xo_get(self::MANAGED_CLASS_OPTIONS, $options) : array();
             //no additional base classes :
             if ($baseClasses == null || !count($baseClasses)) {
                 $this->_object = new $_managedClass($_ctrArgs);
             } else {
                 //mixin new base classes
                 xapp_import('xapp.Commons.ClassMixer');
                 $newClassName = "NEW_" . $_managedClass;
                 XApp_ClassMixer::create_mixed_class($newClassName, $_managedClass, $baseClasses);
                 $this->_object = new $newClassName($_ctrArgs);
             }
         }
         if ($this->_object) {
             if (method_exists($this->_object, 'init')) {
                 $this->_object->init();
             }
         }
     }
 }
Example #6
0
 public static function run($cmd, array $args = array(), $return = null, $options = array())
 {
     self::_escapeArguments($args);
     error_log("run " . $cmd);
     if (!xo_has(self::OPTION_BACKGROUND, $options)) {
         $options[self::OPTION_BACKGROUND] = true;
     }
     $command = $cmd . " " . implode(" ", $args);
     $os = PHP_OS;
     $isWindows = false;
     switch ($os) {
         case "WINNT":
             $isWindows = true;
             $command = str_replace('/', '\\', $command);
     }
     if (xo_has(self::OPTION_STDOUT_TO, $options)) {
         $command .= " >> " . xo_get(self::OPTION_STDOUT_TO, $options);
     }
     if (xo_has(self::OPTION_WORKING_PATH, $options)) {
         $working_path = xo_get(self::OPTION_WORKING_PATH, $options);
         if (!$isWindows) {
             $command = "cd {$working_path} ; " . $command;
         } else {
             if (xo_get(self::OPTION_BACKGROUND, $options)) {
                 $command = "cd {$working_path} & start " . $command;
             } else {
                 $command = "cd {$working_path} & " . $command;
             }
         }
     }
     if (xo_get(self::OPTION_BACKGROUND, $options)) {
         if (xo_get(self::OPTION_PRE_DELAY, $options)) {
             // Add 1 second delay
             $command = "sleep 1 ; " . $command;
         }
         if (!$isWindows) {
             $command .= " & ";
             ignore_user_abort(true);
             register_shutdown_function(array(new self(), '__exec'), $command);
             $result = "Postponed: {$command}";
         } else {
             ignore_user_abort(true);
             register_shutdown_function(array(new self(), '__exec'), $command);
             $result = "Postponed: {$command}";
         }
     } else {
         $result = self::__exec($command);
     }
     return $result;
 }