/** * Constructor * * @param int $flags The error flag for the template engine, must be one of the * class `_ERRORS` constants */ protected function init($flags = TemplateEngine::NO_ERRORS) { Config::load('Assets\\Composer\\TemplateEngineConfig'); $this->setFlags($flags); $this->template = new Template(); $this->view = new View(); $this->registry = new Registry(); $this->setPageLayout(self::$default_page_layout); }
/** * 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); }
/** * 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())); } } }
/** * Validating the autoload generator class to use * * @param string $generator_class * @return bool */ public static function validateAutoloadGenerator($generator_class) { if (class_exists($generator_class)) { $parents = class_parents($generator_class); $autoload_abstract = Config::getInternal('assets-autoload-generator-abstract'); return in_array($autoload_abstract, $parents); } return false; }
/** * Build the complete database array * * @return array */ public function getFullDb() { $filesystem = new Filesystem(); $config = $this->_composer->getConfig(); $assets_db = $this->_autoloader->getRegistry(); $vendor_dir = $this->_autoloader->getAssetsInstaller()->getVendorDir(); $app_base_path = $this->_autoloader->getAssetsInstaller()->getAppBasePath(); $assets_dir = str_replace($app_base_path . '/', '', $this->_autoloader->getAssetsInstaller()->getAssetsDir()); $assets_vendor_dir = str_replace($app_base_path . '/' . $assets_dir . '/', '', $this->_autoloader->getAssetsInstaller()->getAssetsVendorDir()); $document_root = $this->_autoloader->getAssetsInstaller()->getDocumentRoot(); $extra = $this->_package->getExtra(); $root_data = $this->parseComposerExtra($this->_package, $app_base_path, ''); if (!empty($root_data)) { $root_data['relative_path'] = '../'; $assets_db[$this->_package->getPrettyName()] = $root_data; } $vendor_path = strtr(realpath($vendor_dir), '\\', '/'); $rel_vendor_path = $filesystem->findShortestPath(getcwd(), $vendor_path, true); $local_repo = $this->_composer->getRepositoryManager()->getLocalRepository(); $package_map = $this->buildPackageMap($this->_composer->getInstallationManager(), $this->_package, $local_repo->getPackages()); foreach ($package_map as $i => $package) { if ($i === 0) { continue; } $package_object = $package[0]; $package_install_path = $package[1]; if (empty($package_install_path)) { $package_install_path = $app_base_path; } $package_name = $package_object->getPrettyName(); $data = $this->parseComposerExtra($package_object, $this->_autoloader->getAssetsInstaller()->getAssetsInstallPath($package_object), str_replace($app_base_path . '/', '', $vendor_path) . '/' . $package_object->getPrettyName()); if (!empty($data)) { $assets_db[$package_name] = $data; } } $full_db = array('assets-dir' => $assets_dir, 'assets-vendor-dir' => $assets_vendor_dir, 'document-root' => $document_root, 'cache-dir' => isset($extra['cache-dir']) ? $extra['cache-dir'] : Config::getDefault('cache-dir'), 'cache-assets-dir' => isset($extra['cache-assets-dir']) ? $extra['cache-assets-dir'] : Config::getDefault('cache-assets-dir'), 'packages' => $assets_db); return $full_db; }
/** * 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; }