public function init(array $params = array()) { // Save dbQuery instance $this->query = dbQuery('structure'); // Fire new event after creating form tabs Event::subscribe('samsoncms.material.form.created', array($this, 'renderMaterialTab')); }
/** * Module initialization stage. * * @see ModuleConnector::init() * * @param array $params Initialization parameters * * @return bool True if resource successfully initialized */ public function init(array $params = array()) { // Subscribe to core template rendering event Event::subscribe('core.rendered', [$this, 'renderTemplate']); Event::subscribe(Compressor::E_CREATE_RESOURCE_LIST, [$this, 'getResources']); // Set default dependency as local file manager $this->fileManager = $this->fileManager ?: new LocalFileManager(); $this->resourceManager = new ResourceManager($this->fileManager); ResourceManager::$cacheRoot = $this->cache_path; ResourceManager::$webRoot = getcwd(); ResourceManager::$projectRoot = dirname(ResourceManager::$webRoot) . '/'; // Get loaded modules $moduleList = $this->system->getContainer()->getServices('module'); // Event for modification of resource list Event::fire(self::E_MODULES, [&$moduleList]); $appResourcePaths = $this->getAssets($moduleList); // Get assets $this->resources = $this->resourceManager->manage($appResourcePaths); // Fire completion event Event::fire(self::E_FINISHED, [&$this->resources]); // Get asset URLs $this->resourceUrls = array_map([$this, 'getAssetCachedUrl'], $this->resources); // Continue parent initialization return parent::init($params); }
/** * Module initialization. * * @param array $params Initialization parameters collection * @return bool Initialization result */ public function init(array $params = array()) { //[PHPCOMPRESSOR(remove,start)] // Create SamsonPHP routing table from loaded modules $rg = new GenericRouteGenerator($this->system->module_stack); // Generate web-application routes $routes = $rg->generate(); $routes->add($this->findGenericDefaultAction()); // Create cache marker $this->cacheFile = $routes->hash() . '.php'; // If we need to refresh cache if ($this->cache_refresh($this->cacheFile)) { $generator = new Structure($routes, new \samsonphp\generator\Generator()); // Generate routing logic function $routerLogic = $generator->generate(); // Store router logic in cache file_put_contents($this->cacheFile, '<?php ' . "\n" . $routerLogic); } require $this->cacheFile; //[PHPCOMPRESSOR(remove,end)] // This should be change to receive path as a parameter on initialization $pathParts = explode(Route::DELIMITER, $_SERVER['REQUEST_URI']); SamsonLocale::parseURL($pathParts); $this->requestURI = implode(Route::DELIMITER, $pathParts); // Subscribe to samsonphp\core routing event \samsonphp\event\Event::subscribe('core.routing', array($this, 'router')); // Continue initialization return parent::init($params); }
/** Module initialization logic */ public function init(array $params = array()) { $this->enabled = true; // Subscribe to resourcer event \samsonphp\event\Event::subscribe('resourcer.updated', array($this, 'enable')); \samsonphp\event\Event::subscribe('core.rendered', array($this, 'renderToken')); }
/** Module preparation stage handler */ public function prepare(array $params = []) { // Subscribe for CSS handling Event::subscribe(Router::E_RESOURCE_COMPILE, [$this, 'compile']); Event::subscribe(Compressor::E_RESOURCE_COMPRESS, [$this, 'deCompile']); return parent::prepare($params); }
public function init(array $params = array()) { $this->request = url(); // Old applications main page rendering Event::subscribe(\samsoncms\cms\Application::EVENT_IS_CMS, array($this, 'authorize')); // Call parent initialization return parent::init($params); }
public function init(array $params = array()) { $this->request = url(); // Old applications main page rendering Event::subscribe(\samsoncms\cms\Application::EVENT_IS_CMS, array($this, 'authorize')); Event::subscribe(Compressor::E_CREATE_MODULE_LIST, array($this, 'getModuleList')); // Call parent initialization return parent::init($params); }
/** Universal controller action */ public function __handler() { // Render menu \samsonphp\event\Event::subscribe('template.menu.rendered', array($this, 'subMenuHandler')); $html = ''; // Fire event when application help is rendered \samsonphp\event\Event::fire('help.content.rendered', array(&$html, $this)); // Prepare view $this->view('index')->title(t($this->name, true))->set('content', $html); }
/** Universal controller action */ public function __handler($category = null, $subCategory = null, $subSubCategory = null) { // Render menu and current controller parameters \samsonphp\event\Event::subscribe('template.menu.rendered', array($this, 'subMenuHandler'), array($category, $subCategory, $subSubCategory)); $html = ''; // Fire event when application help is rendered \samsonphp\event\Event::fire('help.content.rendered', array(&$html, $category, $subCategory, $subSubCategory, $this)); // Prepare view $this->view('index')->title(t($this->name, true))->set('content', $html); }
/** * Initialize module * @param array $params Collection of parameters * @return bool True if success */ public function init(array $params = array()) { // TODO: Should be change to DI in future // Set pointer to file service $this->fs = $this->system->module('fs'); // Subscribe to material form created event for custom tab rendering Event::subscribe('samsoncms.material.form.created', array($this, 'tabBuilder')); // Subscribe to event - add gallery field additional field type Event::subscribe('cms_field.select_create', array($this, 'fieldSelectCreate')); return parent::init($params); }
/** * ExternalModule constructor. * * @param string $path * @param ResourcesInterface $resources * @param SystemInterface $system */ public function __construct($path, ResourcesInterface $resources, SystemInterface $system) { // Module identifier not specified - set it to NameSpace\Classname if (!isset($this->id[0])) { // Generate identifier from module class $this->id = strtolower(str_replace(__NS_SEPARATOR__, '_', get_class($this))); } // Subscribe to an config ready core event Event::subscribe('core.started', array(&$this, 'init')); // Call parent constructor parent::__construct($this->id, $path, $resources, $system); }
public function testInitAndTemplateRender() { $files = [ResourceManager::T_JS => [__DIR__ . '/test.js'], ResourceManager::T_CSS => [__DIR__ . '/test.css']]; Event::subscribe(Router::E_FINISHED, function (&$resources) use($files) { $resources = $files; }); $this->module->init([]); $view = '<body><head></head></body>'; $this->module->renderTemplate($view); $this->assertEquals('<body><head><link type="text/css" rel="stylesheet" property="stylesheet" href="/tests/test.css"> </head><script type="text/javascript" src="/tests/test.js"></script> </body>', $view); }
public function init(array $params = array()) { // Save dbQuery instance $this->query = dbQuery('structure'); // Fire new event after creating form tabs Event::subscribe('samsoncms.material.form.created', array($this, 'renderMaterialTab')); // Subscribe for render index file and include seo tags to it Event::subscribe('core.rendered', array($this, 'templateRenderer')); // Subscribe for Event::subscribe('samson.cms.web.materialtable.add', array($this, 'addDynamicTags')); // Subscribe for Event::subscribe('samson.cms.web.materialtable.get.table', array($this, 'renderContentElement')); }
/** SamsonFramework load preparation stage handler */ public function prepare(array $params = []) { $moduleCachePath = array_key_exists('cachePath', $params) ? $params['cachePath'] : $this->cache_path; $this->dependencyCache = $moduleCachePath . self::DEPENDENCY_CACHE; // Load file manager $this->fileManager = array_key_exists('fileManager', $params) ? $params['fileManager'] : new LocalFileManager(); // Read previous cache file if ($this->fileManager->exists($this->dependencyCache)) { $this->dependencies = unserialize($this->fileManager->read($this->dependencyCache)); } $this->less = new \lessc(); Event::subscribe(Router::E_RESOURCE_COMPILE, [$this, 'compiler']); Event::subscribe(Router::E_FINISHED, [$this, 'cacheDependencies']); return parent::prepare(); }
public function init(array $params = array()) { //trace('cmsInit'); // Old applications main page rendering Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer')); // Old applications menu rendering Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer')); Event::subscribe('samson.url.build', array($this, 'buildUrl')); Event::subscribe('samson.url.args.created', array($this, 'parseUrl')); Event::subscribe(Module::EVENT_ROUTE_FOUND, array($this, 'activeModuleHandler')); Event::subscribe('samsonphp.router.create.module.routes', array($this, 'updateCMSPrefix')); //[PHPCOMPRESSOR(remove,start)] $moduleList = $this->system->module_stack; foreach ($this->system->module_stack as $id => $module) { if (!$this->isModuleDependent($module) && $id != 'core' && !$this->ifModuleRelated($module)) { unset($moduleList[$id]); } } // Generate resources for new module $this->system->module('resourcer')->generateResources($moduleList, $this->path() . 'app/view/index.php'); //[PHPCOMPRESSOR(remove,end)] // Call parent initialization return parent::init($params); }
/** * Init module * @param array $params */ public function init(array $params = array()) { // Call parent handler parent::init($params); // Subscribe to payment gate init event Event::subscribe('commerce.gateinited', array($this, 'addGate')); // Subscribe to commerce core initialization Event::subscribe('commerce.init.module.commerce.core', array($this, 'initCommerceCore')); }
/** * Switch active environment * @param string $environment Configuration environment identifier */ public function change($environment = Scheme::BASE) { // Switch to configuration environment $this->active =& $this->schemes[$environment]; // Subscribe active configuration scheme to core module configure event Event::subscribe('core.module.configure', array($this, 'configure')); // If we have successfully changed configuration scheme if (!isset($this->active)) { // Signal error Event::fire('error', array($this, 'Cannot change configuration scheme to [' . $environment . '] - Configuration scheme does not exists')); // Set global scheme as active $this->active =& $this->schemes[Scheme::BASE]; } }
/** @inheritdoc */ public function init(array $params = array()) { //[PHPCOMPRESSOR(remove,start)] $this->prepareDictionary(); //[PHPCOMPRESSOR(remove,end)] // Subcribe for Event::subscribe('core.rendered', array($this, 'templateRenderer')); }
public function testAfterLoadEventChangedValue() { $moduleAlias = 'alias'; $loadedAlias = ''; $afterEventID = Event::subscribe(Core::E_AFTER_LOADED, function (&$core, &$module, &$alias) use(&$loadedAlias) { $loadedAlias = $alias; }); $this->core->load(new TestModule(), $moduleAlias); $this->assertEquals($moduleAlias, $loadedAlias); Event::unsubscribe(Core::E_AFTER_LOADED, $afterEventID); }
/** * Module initialization. * * @param array $params Initialization parameters collection * @return bool Initialization result */ public function init(array $params = array()) { //[PHPCOMPRESSOR(remove,start)] // Create SamsonPHP routing table from loaded modules $rg = new GenericRouteGenerator($this->system->module_stack); // Generate web-application routes $routes = $rg->generate(); $routes->add($this->findGenericDefaultAction()); // Create cache marker $this->cacheFile = $routes->hash() . '.php'; // If we need to refresh cache if ($this->cache_refresh($this->cacheFile)) { $generator = new Structure($routes, new \samsonphp\generator\Generator()); // Generate routing logic function $routerLogic = $generator->generate(); // Store router logic in cache file_put_contents($this->cacheFile, '<?php ' . "\n" . $routerLogic); } require $this->cacheFile; //[PHPCOMPRESSOR(remove,end)] // Set locale resolver mode SamsonLocale::$leaveDefaultLocale = $this->browserLocaleRedirect; // This should be change to receive path as a parameter on initialization $pathParts = array_values(array_filter(explode(Route::DELIMITER, $_SERVER['REQUEST_URI']))); // Parse URL and store locale found bug $localeFound = SamsonLocale::parseURL($pathParts, $this->browserLocaleRedirect); // Gather URL path parts with removed locale placeholder $this->requestURI = implode(Route::DELIMITER, $pathParts); // Get localization data $current = SamsonLocale::current(); $default = SamsonLocale::$defaultLocale; // Browser agent language detection logic if ($this->browserLocaleRedirect && !$localeFound) { // Redirect to browser language $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); // Is browser language supported by application $langSupport = in_array($lang, SamsonLocale::get(), true); /** * If browser language header is supported by our web-application and we are already not on that locale * and current locale is not default. */ if ($current === $default && $current !== $lang && $langSupport) { header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $lang . '/' . $this->requestURI); exit; } elseif (!$langSupport || $lang === $current) { SamsonLocale::$leaveDefaultLocale = false; } } // Subscribe to samsonphp\core routing event \samsonphp\event\Event::subscribe('core.routing', array($this, 'router')); // Continue initialization return parent::init($params); }
/** Module initialization */ public function init(array $params = array()) { \samsonphp\event\Event::subscribe('help.content.rendered', array($this, 'help')); \samsonphp\event\Event::subscribe('help.submenu.rendered', array($this, 'helpMenu')); }
/** Application initialization */ public function init(array $params = array()) { // Find all applications that needs access rights to it $accessibleApplications = array('template' => t('Главная страница', true), Right::APPLICATION_ACCESS_ALL => Right::APPLICATION_ACCESS_ALL); // Iterate all loaded applications foreach (self::$loaded as $application) { // Iterate only applications with names $accessibleApplications[$application->id] = $application->name; } // Iterate all applications that needs access rights foreach ($accessibleApplications as $accessibleApplicationID => $accessibleApplicationName) { // Try to find this right in db if (!$this->query->className('right')->cond('Name', Right::APPLICATION_ACCESS_TEMPLATE . $accessibleApplicationID)->first() && isset($accessibleApplicationName[0])) { $right = new Right(); $right->Name = Right::APPLICATION_ACCESS_TEMPLATE . strtoupper($accessibleApplicationID); $right->Description = $accessibleApplicationID != Right::APPLICATION_ACCESS_ALL ? t('Доступ к приложению', true) . ' "' . $accessibleApplicationName . '"' : t('Полный доступ ко всем приложениям', true); $right->Active = 1; $right->save(); } } // Subscribe to core security event \samsonphp\event\Event::subscribe('core.security', array($this, 'handle')); }
/** Module initialization */ public function init(array $params = array()) { \samsonphp\event\Event::subscribe('help.content.rendered', array($this, 'help')); \samsonphp\event\Event::subscribe('help.submenu.rendered', array($this, 'helpMenu')); //[PHPCOMPRESSOR(remove,start)] // Check if it is main application class if (get_class($this) === __CLASS__) { // TODO db() $cacheGenerator = new CacheGenerate(db()); // Load generated modules $cacheGenerator->loadModules($this->system, $this->cache_path); } //[PHPCOMPRESSOR(remove,end)] }
/** * SamsonCMS initialization stage handler * * @param array $params Initialization parameters * * @return bool Initialization stage result */ public function init(array $params = array()) { // Old applications main page rendering Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer')); // Old applications menu rendering Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer')); Event::subscribe('samson.url.build', array($this, 'buildUrl')); Event::subscribe('samson.url.args.created', array($this, 'parseUrl')); Event::subscribe(Module::EVENT_ROUTE_FOUND, array($this, 'activeModuleHandler')); Event::subscribe('samsonphp.router.create.module.routes', array($this, 'updateCMSPrefix')); Event::subscribe(Compressor::E_CREATE_MODULE_LIST, array($this, 'getModuleList')); //url()->parse(); $this->template = $this->path() . 'app/view/index.php'; // Generate resources for new module //[PHPCOMPRESSOR(remove,start)] //$this->system->module('resourcer')->generateResources($this->cmsModuleList, $this->path() . 'app/view/index.php'); //[PHPCOMPRESSOR(remove,end)] }
public function init(array $params = array()) { \samsonphp\event\Event::subscribe('samson.cms.input.table.render', array($this, 'renderForTable')); }
/** Module initialization */ public function init(array $params = array()) { // Subscribe to input change event \samsonphp\event\Event::subscribe('samson.cms.input.change', array($this, 'inputUpdateHandler')); }
/** * Generic wrap for Event system subscription. * @see \samson\core\\samsonphp\event\Event::subscribe() * * @param string $key Event identifier * @param callable $handler Event handler * @param array $params Event parameters * * @return $this Chaining */ public function subscribe($key, $handler, $params = array()) { Event::subscribe($key, $handler, $params); return $this; }
/** SamsonFramework load preparation stage handler */ public function prepare() { Event::subscribe(ResourceRouter::EVENT_CREATED, array($this, 'renderer')); $this->less = new \lessc(); return true; }
/** * Module preparation stage. * * @return bool Preparation stage result */ public function prepare() { // TODO: Should be binded to compressor events instead of resource events // Bind resource router static resource creation event Event::subscribe(Router::E_RESOURCE_COMPILE, array($this, 'renderer')); }
public function init(array $params = array()) { Event::subscribe('samson.cms.input.change', array($this, 'saveFieldHandler')); return parent::init($params); }