Ejemplo n.º 1
0
 /**
  * コンストラクタ
  *
  * @return void
  **/
 public function __construct()
 {
     $reader = new Yaml();
     $reader->setYamlDecoder(array(new YamlParser(), 'parse'));
     $yaml_data = $reader->fromFile(ROOT . '/' . $this->plugins_yml_path);
     $this->plugins = $yaml_data['Plugins'];
 }
Ejemplo n.º 2
0
 /**
  * Process the array for @include
  *
  * @param  array $data
  * @return array
  * @throws RuntimeException
  */
 protected function process(array $data)
 {
     $data = parent::process($data);
     foreach ($data as $key => $value) {
         if (trim($key) === '@includes') {
             if ($this->directory === null) {
                 throw new RuntimeException('Cannot process @includes statement for a json string');
             }
             unset($data[$key]);
             foreach ($value as $file) {
                 $reader = clone $this;
                 $data = ArrayUtils::merge($data, $reader->fromFile($this->directory . '/' . $file));
             }
         }
         if (trim($key) === '@optional') {
             $optionals = (array) $data[$key];
             if ($this->directory === null) {
                 throw new RuntimeException('Cannot process @optional statement for a json string');
             }
             unset($data[$key]);
             foreach ($optionals as $optional) {
                 $filename = $this->directory . '/' . $optional;
                 if (file_exists($filename)) {
                     $reader = clone $this;
                     $data = ArrayUtils::merge($data, $reader->fromFile($filename));
                 }
             }
         }
         if (trim($key) === '@include_php') {
             $optionals = (array) $data[$key];
             if ($this->directory === null) {
                 throw new RuntimeException('Cannot process @optional statement for a json string');
             }
             unset($data[$key]);
             foreach ($optionals as $optional) {
                 $filename = $this->directory . '/' . $optional;
                 if (file_exists($filename)) {
                     $data = ArrayUtils::merge($data, include $filename);
                 }
             }
         }
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Creates a package from existing PHP code
  * @param string folder - the source folder
  * @param string destination - the destination folder
  * @param string name - The name of the package
  * @param string version - The version release of the package
  */
 public function packAction()
 {
     $folder = $this->getRequest()->getParam('folder');
     $destination = $this->getRequest()->getParam('destination');
     $zpk = $this->serviceLocator->get('zpk');
     $content = "";
     $adjustedVendorDir = "";
     $adjustedProperties = array();
     $hasComposerScripts = false;
     ignore_user_abort(true);
     if (file_exists($folder . '/vendor.original')) {
         // The directory structure was not restored to its previous state. Try to fix this.
         foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder . '/vendor', RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $item) {
             unlink($item);
         }
         rename($folder . '/vendor.original', $folder . '/vendor');
     }
     ignore_user_abort(false);
     if ($this->getRequest()->getParam('composer') && file_exists($folder . '/composer.json')) {
         // Enable rudimentary composer support
         $composer = $this->serviceLocator->get('composer');
         $requirements = $composer->getMeta($folder, "require");
         if (count($requirements)) {
             $dependancies = array();
             foreach ($requirements as $name => $version) {
                 if ($name == "php") {
                     // add in the deployment.xml dependancy on this PHP version
                     $dependancies['php'] = self::convertVersion($version);
                 } elseif (strpos($name, 'ext-') === 0) {
                     // add in the deployment.xml dependancy on this PHP extension
                     $name = substr($name, 4);
                     $dependancies['extension'][$name] = self::convertVersion($version);
                 } elseif (strpos($name, 'lib-') === 0) {
                     // @todo: skip for now
                 } else {
                     $dependandPackages[$name] = $version;
                     $dependancies['library'][] = array_merge(array('name' => self::normalizeLibName($name)), self::convertVersion($version));
                 }
             }
             if (count($dependancies['library'])) {
                 $composerOptions = $this->getRequest()->getParam('composer-options') ?: null;
                 $packages = $composer->install($folder, $composerOptions);
                 foreach ($packages as $library => $version) {
                     $version = self::normalizeVersion($version);
                     $libraryFolder = $folder . '/vendor/' . $library;
                     $library = self::normalizeLibName($library);
                     $zpk->create($libraryFolder, array('type' => 'library', 'name' => $library, 'version' => array('release' => $version), 'appdir' => ''));
                     $zpkFile = $zpk->pack($libraryFolder, $destination, "{$library}-{$version}.zpk");
                     $content .= $zpkFile . "\n";
                 }
             }
             if (!empty($dependancies)) {
                 $zpk->updateMeta($folder, array('dependencies' => array('required' => $dependancies)));
             }
             $composerFile = $this->serviceLocator->get('Composer\\File');
             $adjustedVendorDir = $composerFile->adjustAutoloader($folder);
             $scripts = $composer->getMeta($folder, "scripts");
             if (!empty($scripts)) {
                 $hasComposerScripts = true;
                 $distFiles = $this->getRequest()->getParam('composer-dist-files');
                 $userParams = array();
                 if (!count($distFiles)) {
                     error_log('WARNING: If you have user parameters then you have to use --composer-dist-files to point to the YAML dist files.');
                 } else {
                     // Read the parameters from composer-dist-files are specified it gets the parameters from them and puts them as zpk parameters (with default values)
                     $yaml = new YamlReader(array('Spyc', 'YAMLLoadString'));
                     foreach ($distFiles as $file) {
                         $data = $yaml->fromFile($file);
                         $userParams = array_merge($userParams, $data['parameters']);
                     }
                 }
                 if (!empty($userParams)) {
                     // convert the parameters to deployment.xml ZPK parameters
                     $zpk->updateParameters($folder, $userParams);
                 }
                 $composerFile->copyComposerFiles($folder);
                 $adjustedProperties = $composerFile->adjustDeploymentProperties($folder);
                 $composerFile->writePostStage($folder);
             }
         }
     }
     ignore_user_abort(true);
     if ($hasComposerScripts) {
         $xml = new \SimpleXMLElement(file_get_contents($folder . '/deployment.xml'));
         if (!isset($xml->scriptsdir)) {
             $zpk->updateMeta($folder, array('scriptsdir' => 'scripts'));
         }
     }
     if ($adjustedVendorDir) {
         rename($folder . '/vendor', $folder . '/vendor.original');
         rename($adjustedVendorDir, $folder . '/vendor');
     }
     $zpkFile = $zpk->pack($folder, $destination, $this->getRequest()->getParam('name'), $adjustedProperties, $this->getRequest()->getParam('version'));
     if ($adjustedVendorDir) {
         rename($folder . '/vendor', $adjustedVendorDir);
         rename($folder . '/vendor.original', $folder . '/vendor');
     }
     ignore_user_abort(false);
     $content .= $zpkFile . "\n";
     $this->getResponse()->setContent($content);
     return $this->getResponse();
 }
 protected function writeConfig()
 {
     $configPath = ROOT_PATH . "/module/Scloud/config/openstack.yaml";
     $tenantService = $this->getServiceLocator()->get("tenant_service");
     $roleService = $this->getServiceLocator()->get("role_service");
     if (!file_exists($configPath)) {
         $config = new Config(array(), true);
         $config->openstack = array();
         $tenantService->getToken();
         $config->openstack->admin_tenant_id = $tenantService->getTenantId("admin");
         $roleService->getToken();
         $config->openstack->member_role_id = $roleService->getRoleId(array("role_name" => "Member"));
         $writer = new YamlWriter();
         file_put_contents($configPath, $writer->toString($config));
     }
     $reader = new YamlReader();
     return $reader->fromFile($configPath);
 }
Ejemplo n.º 5
0
 /**
  * call and read specified configuration
  *
  * @param string $path
  * @param string $type
  * @return array
  */
 protected function configurationStrategy($path, $type)
 {
     $config = [];
     if (!file_exists($path)) {
         throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
     }
     switch ($type) {
         case 'array':
             $config = (include_once $path);
             break;
         case 'ini':
             $reader = new Reader\Ini();
             $config = $reader->fromFile($path);
             break;
         case 'xml':
             $reader = new Reader\Xml();
             $config = $reader->fromFile($path);
             break;
         case 'json':
             $reader = new Reader\Json();
             $config = $reader->fromFile($path);
             break;
         case 'yaml':
             $reader = new Reader\Yaml(['Spyc', 'YAMLLoadString']);
             $config = $reader->fromFile($path);
             break;
     }
     return $config;
 }