/** * @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 testGetNamespace() { $this->assertInternalType('string', CM_Util::getNamespace('CM_Util')); $this->assertNull(CM_Util::getNamespace('NoNamespace', true)); try { CM_Util::getNamespace('NoNamespace', false); $this->fail('Namespace detected in a className without namespace.'); } catch (CM_Exception_Invalid $ex) { $this->assertContains('Could not detect namespace of `NoNamespace`.', $ex->getMessage()); } }
/** * @param ReflectionClass $reflection * @return null|string */ protected function _generatePageContent(ReflectionClass $reflection) { if ($reflection->isSubclassOf('CM_Page_Abstract')) { $parentClassName = $reflection->getParentClass()->getName(); $content = "{extends file=\$render->getLayoutPath('" . $this->_extractTemplateName($parentClassName) . "default.tpl'"; if ($reflection->isAbstract()) { $namespace = CM_Util::getNamespace($parentClassName); $content .= ", '" . $namespace . "'"; } $content .= ")}\n"; return $content; } return null; }
/** * @throws CM_Exception_Invalid * @return string */ protected static function _getClassNamespace() { return CM_Util::getNamespace(get_called_class()); }
/** * @param string $className * @param string $name * @param string $domain * @throws CM_Exception_Invalid */ public function createSite($className, $name, $domain) { $appInstallation = $this->_getAppInstallation(); $generatorPhp = new CM_Tools_Generator_Class_Php($appInstallation, $this->_getStreamOutput()); $generatorConfig = new CM_Tools_Generator_Config($appInstallation, $this->_getStreamOutput()); $moduleName = CM_Util::getNamespace($className); $parentClassName = $generatorPhp->getParentClassName($className); if (!is_a($parentClassName, 'CM_Site_Abstract', true)) { throw new CM_Exception_Invalid('Detected parent className `' . $parentClassName . '` is not a `CM_Site_Abstract`.'); } $classBlock = $generatorPhp->createClass($className); $classBlock->addMethod(new \CodeGenerator\MethodBlock('__construct', "parent::__construct();\n\$this->_setModule('{$moduleName}');")); $generatorPhp->createClassFileFromClass($classBlock); $modulePath = $appInstallation->getModulePath($moduleName); $file = new CM_File($modulePath . 'resources/config/default.php', $appInstallation->getFilesystem()); $config = new CM_Config_Node(); $config->{$className}->name = $name; $config->{$className}->emailAddress = 'hello@' . $domain; $generatorConfig->addEntries($file, $config); $file = new CM_File('resources/config/local.php', $appInstallation->getFilesystem()); $config = new CM_Config_Node(); $config->{$className}->url = 'http://www.' . $domain; $config->{$className}->urlCdn = 'http://origin-www.' . $domain; $generatorConfig->addEntries($file, $config); (new CM_App_Cli())->generateConfigInternal(); }
/** * @param string $className * @return string * @throws CM_Exception_Invalid */ protected function _getClassPath($className) { $namespace = CM_Util::getNamespace($className); $namespacePath = $this->_appInstallation->getNamespacePath($namespace); return $namespacePath . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; }
/** * @param string $className * @return string */ public static function getNameByClassName($className) { return str_replace('_', ' ', str_replace(CM_Util::getNamespace($className) . '_Action_', '', $className)); }