/** * @param CM_Frontend_Render $render * @param string $className * @throws CM_Exception */ public function __construct(CM_Frontend_Render $render, $className) { parent::__construct($render); if (!preg_match('#^([^_]+)_([^_]+)_?(.*)$#', $className, $matches)) { throw new CM_Exception('Cannot detect all className parts from view\'s className', null, ['className' => $className]); } list($className, $namespace, $viewType, $viewName) = $matches; $viewPath = $viewType . '/'; if ($viewName) { $viewPath .= $viewName . '/'; } $relativePaths = array(); foreach ($render->getSite()->getThemes() as $theme) { $basePath = $render->getThemeDir(true, $theme, $namespace) . $viewPath; foreach (CM_Util::rglob('*.less', $basePath) as $path) { $relativePaths[] = preg_replace('#^' . $basePath . '#', '', $path); } } foreach (array_unique($relativePaths) as $path) { $prefix = '.' . $className; if ($path !== 'default.less' && strpos($path, '/') === false) { $prefix .= '.' . preg_replace('#.less$#', '', $path); } $file = $render->getLayoutFile($viewPath . $path, $namespace); $this->add($file->read(), $prefix); } }
/** * @param CM_Frontend_Render $render * @throws CM_Exception */ public function __construct(CM_Frontend_Render $render) { parent::__construct($render); $this->addVariables(); $file = new CM_File(DIR_PUBLIC . 'static/css/library/icon.less'); if ($file->exists()) { $this->add($file->read()); } foreach (array_reverse($render->getSite()->getModules()) as $moduleName) { foreach (array_reverse($render->getSite()->getThemes()) as $theme) { foreach (CM_Util::rglob('*.less', $render->getThemeDir(true, $theme, $moduleName) . 'css/') as $path) { $file = new CM_File($path); $this->add($file->read()); } } } $viewClasses = CM_View_Abstract::getClassChildren(true); foreach ($viewClasses as $viewClassName) { $validModule = in_array(CM_Util::getNamespace($viewClassName), $render->getSite()->getModules()); $validViewClass = $this->_isValidViewClass($viewClassName); if ($validModule && $validViewClass) { $asset = new CM_Asset_Css_View($this->_render, $viewClassName); $this->add($asset->_getContent()); } } }
public function __construct(CM_Site_Abstract $site) { $content = ''; foreach (array_reverse($site->getModules()) as $moduleName) { $libraryPath = DIR_ROOT . CM_Bootloader::getInstance()->getModulePath($moduleName) . 'client-vendor/after-body/'; foreach (CM_Util::rglob('*.js', $libraryPath) as $path) { $content .= (new CM_File($path))->read() . ';' . PHP_EOL; } } $this->_content = $content; }
private function _setInitialVersion() { $app = CM_App::getInstance(); foreach (CM_App::getInstance()->getUpdateScriptPaths() as $namespace => $path) { $updateFiles = CM_Util::rglob('*.php', $path); $version = array_reduce($updateFiles, function ($initial, $path) { $filename = basename($path); return max($initial, (int) $filename); }, 0); $app->setVersion($version, $namespace); } }
public function __construct(CM_Frontend_Render $render) { parent::__construct($render); $extensions = array('css', 'less'); foreach (array_reverse($render->getSite()->getModules()) as $moduleName) { $libraryPath = DIR_ROOT . CM_Bootloader::getInstance()->getModulePath($moduleName) . 'client-vendor/'; foreach ($extensions as $extension) { foreach (CM_Util::rglob('*.' . $extension, $libraryPath) as $path) { $file = new CM_File($path); $this->add($file->read()); } } } }
/** * @param string $path */ protected function _appendDirectoryGlob($path) { foreach (array_reverse($this->_site->getModules()) as $moduleName) { $initPath = $this->_getPathInModule($moduleName, $path); foreach (CM_Util::rglob('*.js', $initPath) as $filePath) { $content = (new CM_File($filePath))->read(); $this->_js->append($content); } } }
/** * @param string $className * @param boolean|null $includeAbstracts * @return string[] */ public static function getClassChildren($className, $includeAbstracts = null) { $key = CM_CacheConst::ClassChildren . '_className:' . $className . '_abstracts:' . (int) $includeAbstracts; $cache = CM_Cache_Local::getInstance(); if (false === ($classNames = $cache->get($key))) { $pathsFiltered = array(); $paths = array(); foreach (CM_Bootloader::getInstance()->getModules() as $modulePath) { $namespacePaths = CM_Util::rglob('*.php', CM_Util::getModulePath($modulePath) . 'library/'); $paths = array_merge($paths, $namespacePaths); } $regexp = '#\\bclass\\s+(?<name>[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\s+#'; foreach ($paths as $path) { $file = new CM_File($path); $fileContents = $file->read(); if (preg_match($regexp, $fileContents, $matches)) { if (class_exists($matches['name'], true)) { $reflectionClass = new ReflectionClass($matches['name']); if (($reflectionClass->isSubclassOf($className) || interface_exists($className) && $reflectionClass->implementsInterface($className)) && (!$reflectionClass->isAbstract() || $includeAbstracts)) { $pathsFiltered[] = $path; } } } } $classNames = self::getClasses($pathsFiltered); $cache->set($key, $classNames); } return $classNames; }