/** * Generate packages metadata. * Events and modules files. * * @param AbstractPackage[] $packages Packages array. * @param bool $checkManifest Check manifest if it can not be just overwritten. * * @return void */ public function generateMetadata($packages = null, $checkManifest = false) { if (empty($packages)) { $packages = $this->_installedPackages; } if (empty($packages)) { return; } // Check packages metadata directory. $packagesMetadataDirectory = ROOT_PATH . Config::CONFIG_METADATA_PACKAGES; Utilities::fsCheckLocation($packagesMetadataDirectory); $config = ['installed' => PHALCONEYE_VERSION, 'events' => [], 'modules' => []]; foreach ($packages as $package) { if (!$package->enabled) { continue; } $data = $package->getData(); if ($package->type == self::PACKAGE_TYPE_MODULE && !$package->is_system) { $config['modules'][] = $package->name; } // Get package events. if (in_array($package->type, [self::PACKAGE_TYPE_PLUGIN, self::PACKAGE_TYPE_MODULE]) && !$package->is_system) { if (!empty($data) && !empty($data['events'])) { $config['events'] = array_merge($config['events'], $data['events']); } } // If widget is related to module - it has no manifest file. if ($package->type == self::PACKAGE_TYPE_WIDGET && !empty($data) && !empty($data['module'])) { continue; } $packageMetadataFile = $packagesMetadataDirectory . '/' . $this->_getPackageFullName($package) . '.json'; $this->_createManifest($packageMetadataFile, $package->toJson(), $checkManifest); } file_put_contents(ROOT_PATH . Config::CONFIG_METADATA_APP, sprintf('<?php %s return %s;', PHP_EOL, var_export($config, true))); }
/** * Clear assets cache. * * @param bool $refresh Install and compile new assets? * @param string $themeDirectory Theme directory. * * @return void */ public function clear($refresh = true, $themeDirectory = '') { $location = $this->_getLocation(); $files = FsUtilities::fsRecursiveGlob($location, '*'); // get all file names // iterate files foreach ($files as $file) { if (is_file($file)) { @unlink($file); // delete file } } if ($refresh) { $this->installAssets($themeDirectory); } }
/** * Prepare controller. * * @param string|null $action Action name. * * @return void */ public function prepare($action = null) { $this->di = DI::getDefault(); $this->dispatcher = $this->di->get('dispatcher'); $this->cacheData = $this->di->get('cacheData'); if ($this->_widgetName !== null) { if ($this->_widgetModule !== null) { /** @var \Phalcon\Mvc\View $view */ $this->view = $view = $this->di->get('view'); $view->disableLevel(View::LEVEL_LAYOUT); $view->disableLevel(View::LEVEL_MAIN_LAYOUT); if ($action) { $view->pick('../../' . $this->_widgetModule . '/Widget/' . $this->_widgetName . '/' . $action); } } else { /** @var \Phalcon\Mvc\View $view */ $this->view = $view = $this->di->get('view'); $view->disableLevel(View::LEVEL_LAYOUT); $view->disableLevel(View::LEVEL_MAIN_LAYOUT); $view->setVars([], false); if ($action) { $relativePath = Utilities::getRelativePath($view->getViewsDir(), $this->di->get('registry')->directories->widgets); $view->pick($relativePath . $this->_widgetName . '/' . $action); } } } // run init function if (method_exists($this, 'initialize')) { $this->initialize(); } }