Ejemplo n.º 1
0
 /**
  * Install assets from all modules.
  *
  * @param string $themeDirectory Theme directory.
  *
  * @return void
  */
 public function installAssets($themeDirectory = '')
 {
     $location = $this->_getLocation();
     $less = Less::factory();
     $less->setVariables(['baseUrl' => "'" . $this->_config->application->baseUrl . "'"]);
     ///////////////////////////////////
     // Check generated directory.
     ///////////////////////////////////
     if (!is_dir($location . self::GENERATED_STORAGE_PATH)) {
         mkdir($location . self::GENERATED_STORAGE_PATH);
     }
     ///////////////////////////////////
     // Compile themes css.
     ///////////////////////////////////
     if ($this->_config->installed && !empty($themeDirectory)) {
         $themeFiles = glob($themeDirectory . '/*.less');
         FsUtilities::fsCheckLocation($location . 'css/');
         foreach ($themeFiles as $file) {
             $newFileName = $location . 'css/' . basename($file, '.less') . '.css';
             $less->checkedCompile($file, $newFileName);
         }
     }
     ///////////////////////////////////
     // Collect css/js/img from modules.
     ///////////////////////////////////
     $registry = $this->getDI()->get('registry');
     foreach ($registry->modules as $module) {
         // CSS
         $assetsPath = $registry->directories->modules . ucfirst($module) . '/Assets/';
         $path = $location . 'css/' . $module . '/';
         FsUtilities::fsCheckLocation($path);
         $cssFiles = FsUtilities::fsRecursiveGlob($assetsPath . 'css/*');
         $less->addImportDir($themeDirectory);
         foreach ($cssFiles as $file) {
             if (!is_file($file)) {
                 continue;
             }
             $fileName = basename($file);
             $fileNameWithoutExt = basename($file, '.less');
             $additionalPath = str_replace($fileName, '', str_replace($assetsPath . 'css/', '', $file));
             if (pathinfo($file, PATHINFO_EXTENSION) == 'less') {
                 FsUtilities::fsCheckLocation($path . $additionalPath);
                 $newFileName = $path . $additionalPath . $fileNameWithoutExt . '.css';
                 $less->checkedCompile($file, $newFileName);
             } else {
                 copy($file, $path . $additionalPath . $fileName);
             }
         }
         // JS
         $path = $location . 'js/' . $module . '/';
         FsUtilities::fsCheckLocation($path);
         FsUtilities::fsCopyRecursive($assetsPath . 'js', $path, true);
         // IMAGES
         $path = $location . 'img/' . $module . '/';
         FsUtilities::fsCheckLocation($path);
         FsUtilities::fsCopyRecursive($assetsPath . 'img', $path, true);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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)));
 }