Exemplo n.º 1
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->devMode = $factory->getEnvironment() == 'dev';
     $this->imageDir = $factory->getSystemPath('images');
     $this->assetHelper = $factory->getHelper('template.assets');
     $this->avatarHelper = $factory->getHelper('template.avatar');
 }
Exemplo n.º 2
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->cacheDir = $factory->getSystemPath('cache', true);
     $this->env = $factory->getEnvironment();
     $this->configFile = $this->factory->getLocalConfigFile(false);
     $this->containerFile = $this->factory->getKernel()->getContainerFile();
 }
Exemplo n.º 3
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->devMode = $factory->getEnvironment() == 'dev';
     $this->imageDir = $factory->getSystemPath('images');
     $this->assetHelper = $factory->getHelper('template.assets');
     $this->avatarHelper = $factory->getHelper('template.avatar');
     $this->request = $factory->getRequest();
     $this->devHosts = (array) $factory->getParameter('dev_hosts');
 }
Exemplo n.º 4
0
 /**
  * Generates and returns assets
  *
  * @param bool $forceRegeneration
  *
  * @return array
  */
 public function getAssets($forceRegeneration = false)
 {
     static $assets = array();
     if (empty($assets)) {
         $loadAll = true;
         $env = $forceRegeneration ? 'prod' : $this->factory->getEnvironment();
         $rootPath = $this->factory->getSystemPath('assets_root');
         $assetsPath = $this->factory->getSystemPath('assets');
         $assetsFullPath = "{$rootPath}/{$assetsPath}";
         if ($env == 'prod') {
             $loadAll = false;
             //by default, loading should not be required
             //check for libraries and app files and generate them if they don't exist if in prod environment
             $prodFiles = array('css/libraries.css', 'css/app.css', 'js/libraries.js', 'js/app.js');
             foreach ($prodFiles as $file) {
                 if (!file_exists("{$assetsFullPath}/{$file}")) {
                     $loadAll = true;
                     //it's missing so compile it
                     break;
                 }
             }
         }
         if ($loadAll || $forceRegeneration) {
             if ($env == 'prod') {
                 ini_set('max_execution_time', 300);
                 $inProgressFile = "{$assetsFullPath}/generation_in_progress.txt";
                 if (!$forceRegeneration) {
                     while (file_exists($inProgressFile)) {
                         //dummy loop to prevent conflicts if one process is actively regenerating assets
                     }
                 }
                 file_put_contents($inProgressFile, date('r'));
             }
             $modifiedLast = array();
             //get a list of all core asset files
             $bundles = $this->factory->getParameter('bundles');
             $fileTypes = array('css', 'js');
             foreach ($bundles as $bundle) {
                 foreach ($fileTypes as $ft) {
                     if (!isset($modifiedLast[$ft])) {
                         $modifiedLast[$ft] = array();
                     }
                     $dir = "{$bundle['directory']}/Assets/{$ft}";
                     if (file_exists($dir)) {
                         $modifiedLast[$ft] = array_merge($modifiedLast[$ft], $this->findAssets($dir, $ft, $env, $assets));
                     }
                 }
             }
             $modifiedLast = array_merge($modifiedLast, $this->findOverrides($env, $assets));
             //combine the files into their corresponding name and put in the root media folder
             if ($env == "prod") {
                 $checkPaths = array($assetsFullPath, "{$assetsFullPath}/css", "{$assetsFullPath}/js");
                 array_walk($checkPaths, function ($path) {
                     if (!file_exists($path)) {
                         mkdir($path);
                     }
                 });
                 $useMinify = class_exists('\\Minify');
                 foreach ($assets as $type => $groups) {
                     foreach ($groups as $group => $files) {
                         $assetFile = "{$assetsFullPath}/{$type}/{$group}.{$type}";
                         //only refresh if a change has occurred
                         $modified = $forceRegeneration || !file_exists($assetFile) ? true : filemtime($assetFile) < $modifiedLast[$type][$group];
                         if ($modified) {
                             if (file_exists($assetFile)) {
                                 //delete it
                                 unlink($assetFile);
                             }
                             if ($type == 'css') {
                                 $out = fopen($assetFile, 'w');
                                 foreach ($files as $relPath => $details) {
                                     $cssRel = '../../' . dirname($relPath) . '/';
                                     if ($useMinify) {
                                         $content = \Minify::combine(array($details['fullPath']), array('rewriteCssUris' => false, 'minifierOptions' => array('text/css' => array('currentDir' => '', 'prependRelativePath' => $cssRel))));
                                     } else {
                                         $content = file_get_contents($details['fullPath']);
                                         $search = '#url\\((?!\\s*([\'"]?(((?:https?:)?//)|(?:data\\:?:))))\\s*([\'"])?#';
                                         $replace = "url(\$4{$cssRel}";
                                         $content = preg_replace($search, $replace, $content);
                                     }
                                     fwrite($out, $content);
                                 }
                                 fclose($out);
                             } else {
                                 array_walk($files, function (&$file) {
                                     $file = $file['fullPath'];
                                 });
                                 file_put_contents($assetFile, \Minify::combine($files));
                             }
                         }
                     }
                 }
                 unlink($inProgressFile);
             }
         }
         if ($env == 'prod') {
             //return prod generated assets
             $assets = array('css' => array("{$assetsPath}/css/libraries.css?v{$this->version}", "{$assetsPath}/css/app.css?v{$this->version}"), 'js' => array("{$assetsPath}/js/libraries.js?v{$this->version}", "{$assetsPath}/js/app.js?v{$this->version}"));
         } else {
             foreach ($assets as $type => &$typeAssets) {
                 $typeAssets = array_keys($typeAssets);
             }
         }
     }
     return $assets;
 }
Exemplo n.º 5
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     self::$devMode = $factory->getEnvironment() == 'dev';
 }
Exemplo n.º 6
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->cacheDir = $factory->getSystemPath('cache', true);
     $this->env = $factory->getEnvironment();
 }