Ejemplo n.º 1
0
 /**
  * Compiles assets of a given type which are registered.
  *
  * @param  string  $type
  * @return array
  */
 public function getCompiled($type)
 {
     // Get an array of separate assets
     $assets = $this->getSorted($type);
     $compileExtension = $this->getCompileFileExtension($type);
     // If we are not in debug mode, we'll
     // convert them to a collection which
     // means they'll all be combined
     if ($this->debug === false) {
         $collection = $this->createAssetCollection($assets);
         // Loop through all assets in collection and add appropriate
         // filters based off the extension each asset has
         foreach ($collection->all() as $asset) {
             if ($extension = pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION)) {
                 foreach ($this->getFilterInstances($extension) as $filter) {
                     $asset->ensureFilter($filter);
                 }
             }
         }
         $assets = array($collection);
     } else {
         foreach ($assets as $asset) {
             if ($extension = pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION)) {
                 foreach ($this->getFilterInstances($extension) as $filter) {
                     $asset->ensureFilter($filter);
                 }
             }
         }
     }
     $urls = array();
     $cachePath = $this->locationGenerator->getPublicPath($this->cachePath);
     $cachedAssets = $this->themeBag->getFilesystem()->files($cachePath);
     // Loop through assets to ensure they exist
     // and get their URL to append to our array.
     // This is common to non-debug and debug mode.
     foreach ($assets as $asset) {
         $filename = $this->getCompilePrefix() . $this->getCompileFileName($asset, $compileExtension);
         // If our file does not exist at the given path, we'll
         // compile our asset and put it there.
         $path = $cachePath . '/' . $filename;
         if ($this->forceRecompile or !$this->themeBag->getFilesystem()->exists($path)) {
             $asset->load();
             preg_match('/.*_/', $filename, $pattern);
             $pattern = head($pattern);
             foreach ($cachedAssets as $cachedAsset) {
                 if (strpos($cachedAsset, $pattern) !== false) {
                     $this->themeBag->getFilesystem()->delete($cachedAsset);
                 }
             }
             $this->themeBag->getFilesystem()->put($path, $asset->dump());
         }
         $urls[] = $this->locationGenerator->getPathUrl($path);
     }
     // Clears all Asset objects for specified type
     $this->clearQueue($type);
     return $urls;
 }
Ejemplo n.º 2
0
 /**
  * Loads the Theme Info JSON file for the theme.
  *
  * @return void
  */
 protected function loadInfoFile()
 {
     $file = "{$this->path}/theme.json";
     $json = $this->themeBag->getFilesystem()->get($file);
     $data = json_decode($json);
     if (is_null($data) and !is_null($json)) {
         $this->validateSyntax($json, $file);
     }
     $this->validateSchema($data, $file);
     $data = json_decode($json, true);
     $resolver = new NamespacedItemResolver();
     list($this->area, $this->key) = $resolver->parseKey($data['slug']);
     unset($data['slug']);
     $this->setAttributes($data);
 }
Ejemplo n.º 3
0
 /**
  * Create a new theme publisher.
  *
  * @param  \Cartalyst\Themes\ThemeBag  $themeBag
  * @return void
  */
 public function __construct(ThemeBag $themeBag)
 {
     $this->themeBag = $themeBag;
     $this->filesystem = $themeBag->getFilesystem();
 }