/** * Remove the assets of a package * * @param \Composer\Package\PackageInterface $package * @return bool */ protected function removeAssets(PackageInterface $package) { $assets = $this->getPackageAssetsDir($package); if (!$assets) { return; } $target = $this->getAssetsInstallPath($package); if (file_exists($target)) { $this->io->write(sprintf(' - Removing <info>%s</info> assets from <info>%s</info>', $package->getPrettyName(), str_replace(dirname($this->assets_dir) . '/', '', $target))); $this->filesystem->remove($target); Dispatch::unregisterPackage($package, $this); $this->io->write(''); } else { Error::thrower(sprintf('Unable to find assets from package "%s"', $package->getPrettyName()), '\\InvalidArgumentException', __CLASS__, __METHOD__, __LINE__); } }
/** * 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__); } }