/** * Search a configuration value in a package's config or the global config if so * * @param \Composer\Package\PackageInterface $package * @param string $config_entry * @return string */ public static function guessConfigurationEntry(PackageInterface $package, $config_entry) { if (empty($config_entry)) { return array(); } $extra = $package->getExtra(); return isset($extra[$config_entry]) ? $extra[$config_entry] : Config::get($config_entry); }
/** * Initializes installer: creation of all required objects and validating them * * {@inheritDoc} */ public function __construct(IOInterface $io, Composer $composer, $type = 'library') { self::$__io = $io; self::$__composer = $composer; self::$__type = $type; $package = self::$__composer->getPackage(); $config = self::$__composer->getConfig(); $extra = $package->getExtra(); // Config if (isset($extra['assets-config-class'])) { $config_class = $extra['assets-config-class']; if ($this->validateConfig($config_class)) { Config::load($config_class); Config::overload($extra); } else { self::$__io->write(sprintf('<warning>AssetsManager Notice: skipping configuration class "%s": class not found!</warning>', $config_class)); } } // Installer $installer_class = Config::get('assets-package-installer-class'); if (!empty($installer_class)) { if (!$this->validateInstaller($installer_class)) { self::$__io->write(sprintf('<warning>AssetsManager Notice: skipping assets installer class "%s": class not found!</warning>', $installer_class)); $installer_class = Config::getInternal('assets-package-installer-class'); } if (class_exists($installer_class)) { $interfaces = class_implements($installer_class); $installer_interface = Config::getInternal('assets-package-installer-interface'); if (in_array($installer_interface, $interfaces)) { self::$__installer = new $installer_class(self::$__io, self::$__composer, self::$__type); } else { Error::thrower(sprintf('Assets package installer class "%s" must implement interface "%s"!', $installer_class, $installer_interface), '\\DomainException', __CLASS__, __METHOD__, __LINE__); } } else { Error::thrower(sprintf('Assets package installer class "%s" not found!', $installer_class), '\\DomainException', __CLASS__, __METHOD__, __LINE__); } } else { Error::thrower('Assets package installer is not defined!', '\\Exception', __CLASS__, __METHOD__, __LINE__); } // AutoloadGenerator $autoload_class = Config::get('assets-autoload-generator-class'); if (!empty($autoload_class)) { if (!$this->validateAutoloadGenerator($autoload_class)) { self::$__io->write(sprintf('<warning>AssetsManager Notice: skipping autoload generator class "%s": class not found!</warning>', $autoload_class)); $autoload_class = Config::getInternal('assets-autoload-generator-class'); } if (class_exists($autoload_class)) { $parents = class_parents($autoload_class); $autoload_abstract = Config::getInternal('assets-autoload-generator-abstract'); if (in_array($autoload_abstract, $parents)) { self::$__autoloader = $autoload_class::getInstance(self::$__installer); } else { Error::thrower(sprintf('Assets autoload generator class "%s" must extend abstract class "%s"!', $autoload_class, $autoload_abstract), '\\DomainException', __CLASS__, __METHOD__, __LINE__); } } else { Error::thrower(sprintf('Assets autoload generator class "%s" not found!', $installer_class), '\\DomainException', __CLASS__, __METHOD__, __LINE__); } } else { Error::thrower('Assets autoload generator is not defined!', '\\Exception', __CLASS__, __METHOD__, __LINE__); } }
/** * Automatic assets loading from an Assets package declare in a `composer.json` * * @return void * @throws \DomainException if the preset doesn't exist or doesn't implement required interface * @throws \LogicException if the statement doesn't exist */ public function load() { if (!empty($this->_statements)) { return; } foreach ($this->data as $type => $item) { if (!is_array($item)) { $item = array($item); } $use_statements = Config::get('use-statements'); $adapter_name = isset($use_statements[$type]) ? $use_statements[$type] : null; if (!empty($adapter_name)) { $cls_name = 'AssetsManager\\Package\\PresetAdapter\\' . $adapter_name; if (@class_exists($cls_name)) { $interfaces = class_implements($cls_name); $config_interface = Config::getInternal('assets-preset-adapter-interface'); if (in_array($config_interface, $interfaces)) { if (!isset($this->_statements[$type])) { $this->_statements[$type] = array(); } foreach ($item as $item_ctt) { if (!is_array($item_ctt)) { $item_ctt = array($item_ctt); } $statement = new $cls_name($item_ctt, $this); $statement->parse(); $this->_statements[$type][] = $statement; } } else { throw new \DomainException(sprintf('Preset statement class "%s" must implement interface "%s"!', $cls_name, $config_interface)); } } else { throw new \DomainException(sprintf('Preset statement class "%s" not found!', $cls_name)); } } else { throw new \LogicException(sprintf('Unknown preset statement type "%s" in preset "%s"!', $type, $this->getName())); } } }
/** * Build a new preset instance * * @param string $preset_name * @return \AssetsManager\Package\Preset * @throws \DomainException if the preset class can't be found or doesn't implement required interface * @throws \InvalidArgumentException if the preset can't be found */ protected function _buildNewPreset($preset_name) { $preset = isset($this->presets_data[$preset_name]) ? $this->presets_data[$preset_name]['data'] : null; if (!empty($preset)) { $package = $this->getPackage($this->presets_data[$preset_name]['package']); $cls_name = Config::get('assets-preset-class'); if (@class_exists($cls_name)) { $interfaces = class_implements($cls_name); $config_interface = Config::getInternal('assets-preset-interface'); if (in_array($config_interface, $interfaces)) { $preset_object = new $cls_name($preset_name, $preset, $package); return $preset_object; } else { throw new \DomainException(sprintf('Preset class "%s" must implement interface "%s"!', $cls_name, $config_interface)); } } else { throw new \DomainException(sprintf('Preset class "%s" not found!', $cls_name)); } } else { throw new \InvalidArgumentException(sprintf('Unknown preset "%s"!', $preset_name)); } return null; }