Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Example #1
0
 /**
  * Creates a new module.
  *
  * @param ModuleFile|null  $moduleFile  The module file or `null` if the
  *                                      module file could not be loaded.
  * @param string           $installPath The absolute install path.
  * @param InstallInfo|null $installInfo The install info of this module.
  * @param Exception[]      $loadErrors  The errors that happened during
  *                                      loading of the module, if any.
  */
 public function __construct(ModuleFile $moduleFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array())
 {
     Assert::absoluteSystemPath($installPath);
     Assert::allIsInstanceOf($loadErrors, 'Exception');
     // If a module name was set during installation, that name wins over
     // the predefined name in the puli.json file (if any)
     $this->name = $installInfo && null !== $installInfo->getModuleName() ? $installInfo->getModuleName() : ($moduleFile ? $moduleFile->getModuleName() : null);
     if (null === $this->name) {
         $this->name = $this->getDefaultName();
     }
     // The path is stored both here and in the install info. While the
     // install info contains the path as it is stored in the install file
     // (i.e. relative or absolute), the install path of the module is
     // always an absolute path.
     $this->installPath = $installPath;
     $this->installInfo = $installInfo;
     $this->moduleFile = $moduleFile;
     $this->loadErrors = $loadErrors;
     if (!file_exists($installPath)) {
         $this->state = ModuleState::NOT_FOUND;
     } elseif (count($loadErrors) > 0) {
         $this->state = ModuleState::NOT_LOADABLE;
     } else {
         $this->state = ModuleState::ENABLED;
     }
 }
Example #2
0
 /**
  * Creates a new root module file.
  *
  * The file's configuration will inherit its settings from the base
  * configuration passed to the constructor.
  *
  * @param string|null $moduleName The module name. Optional.
  * @param string|null $path       The path where the configuration is
  *                                stored or `null` if this configuration is
  *                                not stored on the file system.
  * @param Config|null $baseConfig The configuration that the module will
  *                                inherit its configuration values from.
  */
 public function __construct($moduleName = null, $path = null, Config $baseConfig = null)
 {
     parent::__construct($moduleName, $path);
     $this->config = new Config($baseConfig);
 }
Example #3
0
 protected function addJsonToModuleFile(stdClass $jsonData, ModuleFile $moduleFile)
 {
     if (isset($jsonData->name)) {
         $moduleFile->setModuleName($jsonData->name);
     }
     if (isset($jsonData->resources)) {
         foreach ($jsonData->resources as $path => $relativePaths) {
             $moduleFile->addPathMapping(new PathMapping($path, (array) $relativePaths));
         }
     }
     if (isset($jsonData->bindings)) {
         foreach ($jsonData->bindings as $uuid => $bindingData) {
             $binding = null;
             $class = isset($bindingData->_class) ? $bindingData->_class : 'Puli\\Discovery\\Binding\\ResourceBinding';
             // Move this code to external classes to allow use of custom
             // bindings
             switch ($class) {
                 case 'Puli\\Discovery\\Binding\\ClassBinding':
                     $binding = new ClassBinding($bindingData->class, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), Uuid::fromString($uuid));
                     break;
                 case 'Puli\\Discovery\\Binding\\ResourceBinding':
                     $binding = new ResourceBinding($bindingData->query, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), isset($bindingData->language) ? $bindingData->language : 'glob', Uuid::fromString($uuid));
                     break;
                 default:
                     continue 2;
             }
             $moduleFile->addBindingDescriptor(new BindingDescriptor($binding));
         }
     }
     if (isset($jsonData->{'binding-types'})) {
         foreach ((array) $jsonData->{'binding-types'} as $typeName => $data) {
             $parameters = array();
             $parameterDescriptions = array();
             if (isset($data->parameters)) {
                 foreach ((array) $data->parameters as $parameterName => $parameterData) {
                     $required = isset($parameterData->required) ? $parameterData->required : false;
                     $parameters[] = new BindingParameter($parameterName, $required ? BindingParameter::REQUIRED : BindingParameter::OPTIONAL, isset($parameterData->default) ? $parameterData->default : null);
                     if (isset($parameterData->description)) {
                         $parameterDescriptions[$parameterName] = $parameterData->description;
                     }
                 }
             }
             $moduleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType($typeName, $parameters), isset($data->description) ? $data->description : null, $parameterDescriptions));
         }
     }
     if (isset($jsonData->depend)) {
         $moduleFile->setDependencies($jsonData->depend);
     }
     if (isset($jsonData->extra)) {
         $moduleFile->setExtraKeys((array) $jsonData->extra);
     }
 }