Exemple #1
0
 /**
  * Build a production collection.
  * 
  * @param  \Basset\Collection  $collection
  * @param  string  $group
  * @return void
  * @throws \Basset\Exceptions\BuildNotRequiredException
  */
 public function buildAsProduction(Collection $collection, $group)
 {
     // Get the assets of the given group from the collection. The collection is also responsible
     // for handling any ordering of the assets so that we just need to build them.
     $assets = $collection->getAssetsWithoutRaw($group);
     $entry = $this->manifest->make($identifier = $collection->getIdentifier());
     // Build the assets and transform the array into a newline separated string. We'll use this
     // as a basis for the collections fingerprint and it will decide as to whether the
     // collection needs to be rebuilt.
     $build = array_to_newlines($assets->map(function ($asset) {
         return $asset->build(true);
     })->all());
     // If the build is empty then we'll reset the fingerprint on the manifest entry and throw the
     // exception as there's no point going any further.
     if (empty($build)) {
         $entry->resetProductionFingerprint($group);
         throw new BuildNotRequiredException();
     }
     $fingerprint = $identifier . '-' . md5($build) . '.' . $collection->getExtension($group);
     $path = $this->buildPath . '/' . $fingerprint;
     // If the collection has already been built and we're not forcing the build then we'll throw
     // the exception here as we don't need to rebuild the collection.
     if ($fingerprint == $entry->getProductionFingerprint($group) and !$this->force and $this->files->exists($path)) {
         throw new BuildNotRequiredException();
     } else {
         $this->files->put($path, $this->gzip($build));
         $entry->setProductionFingerprint($group, $fingerprint);
     }
 }
Exemple #2
0
 /**
  * Output the assets for a collection as defined by the extension.
  * 
  * @return string
  */
 function basset_assets()
 {
     $collections = $responses = array();
     $args = func_get_args();
     // If no arguments were supplied get all the collections and add both the stylesheet and javascript
     // flavors as arguments.
     if (empty($args)) {
         foreach (app('basset')->all() as $identifier => $collection) {
             $args[] = array("{$identifier}.css", "{$identifier}.js");
         }
     }
     array_walk_recursive($args, function ($v, $k) use(&$collections) {
         is_numeric($k) ? $collections[$v] = null : ($collections[$k] = $v);
     });
     foreach ($collections as $collection => $format) {
         $responses[] = app('basset.server')->collection($collection, $format);
     }
     return array_to_newlines($responses);
 }
Exemple #3
0
 /**
  * Format an array of responses and return a string.
  * 
  * @param  mixed  $args
  * @return string
  */
 protected function formatResponse()
 {
     $responses = array();
     foreach (func_get_args() as $response) {
         $responses = array_merge($responses, (array) $response);
     }
     return array_to_newlines($responses);
 }