/** * Fabric method creator * * @param string $place * @param string $place_type * @return afExtjsDesktopStartMenuBuilder * @author Sergey Startsev */ public static function create($place = 'frontend', $place_type = 'app') { $instance = new self(); $path = afExtjsBuilderParser::getHelperPath($place, $place_type); if (!file_exists($path)) { throw new afExtjsDesktopLinksBuilderException("Helper file '{$path}' doesn't exists"); } $instance->setDefinition(afExtjsBuilderParser::create($path)->parse()->get(self::LINKS_IDENTIFICATOR)); $instance->setBuildedInstance(new afExtjsDesktopLinks()); return $instance; }
/** * Saving yml helper definition * * @return afResponse * @author Sergey Startsev */ protected function processSaveHelper() { $response = afResponseHelper::create(); $filesystem = afsFileSystem::create(); $place = $this->getParameter('place', 'frontend'); $place_type = $this->getParameter('place_type', 'app'); $content = preg_replace(array('/\\<\\?php/', '/\\<\\?/', '/\\?\\>/'), array('', '', ''), $this->getParameter('content')); $content = json_decode($content, true); $key = $this->getParameter('key', ''); $permissions = new Permissions(); $is_writable = $permissions->isWritable(sfConfig::get('sf_apps_dir') . '/' . $place . '/config/helper.yml'); if ($is_writable !== true) { return $is_writable; } $helper_path = afExtjsBuilderParser::getHelperPath($place, $place_type); if (file_exists($helper_path)) { if (!is_writable($helper_path)) { return $response->success(false)->message("Please check permissions on helper file"); } $definition = afExtjsBuilderParser::create($helper_path)->parse()->get(); } else { if (!is_writable(dirname($helper_path))) { return $response->success(false)->message("Please check permissions on folder for helper file"); } $definition = array(); $filesystem->touch($helper_path); $filesystem->chmod($helper_path, 0777); } !empty($key) ? $definition[$key] = (array) $content : ($definition = (array) $content); $status = file_put_contents($helper_path, sfYaml::dump($definition, 8)); return $response->success($status)->message($status ? "Helper has been successfully saved" : "Some problems occured while save processing"); }
/** * Process with single item * * @param afExtjsStartMenu $glue_instance * @param Array $definition * @return void * @author Sergey Startsev */ private function getItemInstance(afExtjsStartMenu $glue_instance, array $definition) { $attributes = afExtjsBuilderParser::getAttributes($definition); $children = afExtjsBuilderParser::getChildren($definition); $type = 'item'; if (array_key_exists(self::ITEM_TYPE, $attributes)) { $type = $attributes[self::ITEM_TYPE]; } $type = ucfirst($type); $reflection = new ReflectionClass("afExtjsStartMenu{$type}"); $instance = $reflection->newInstance($glue_instance, $attributes); if (!empty($children)) { $menu_reflection = new ReflectionClass("afExtjsStartMenu"); $menu_instance = $menu_reflection->newInstance($instance); $this->processItems($menu_instance, $children); $menu_instance->end(); } $instance->end(); }
<?php if (file_exists(afExtjsBuilderParser::getHelperPath(sfProjectConfiguration::getActive()->getApplication()))) { afExtjsDesktopLinksBuilder::create(sfProjectConfiguration::getActive()->getApplication())->process()->getBuildedInstance()->end(); } else { afExtjsDesktopLinksBuilder::create('appFlowerPlugin', 'plugin')->process()->getBuildedInstance()->end(); }