Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Builds a filename fingerprint from a pattern if one exists.
  *
  * String Replacement Pattern Pieces
  * ----------------------------------
  *      [collection-name] = Name of the collection
  *      [date:m-d-Y] = Tell it to use the PHP date-time formatting in the filename. Scructure is "date:" followed
  *                   by the standard php date/time formatting (see http://us3.php.net/manual/en/function.date.php)
  *
  * Usage:
  *      You put in a filename string that contains string replace patterns wrapped in square brackets. If you do not
  *      include the collection name replacement pattern somewhere in the pattern string then it will be prepended to
  *      filename.
  *
  *
  * @param Collection $collection
  * @param String     $group
  * @param String     $build
  *
  * @return String
  */
 public function buildFingerprint(Collection $collection, $group, $build)
 {
     //Setup everything we need
     $extension = $collection->getExtension($group);
     $identifier = $collection->getIdentifier();
     $pattern = $this->buildNamePattern;
     /**
      * If we don't have a pattern to follow then we will do it the old fashioned way.
      */
     if (empty($pattern)) {
         return $identifier . '-' . md5($build) . '.' . $extension;
     }
     /**
      * Tokens and token operations.
      *
      * These are the token strings and regular expressions we use to build the collection fingerprints.
      */
     $collectionToken = '[collection-name]';
     $dateTokenRegX = '/\\[date:.+]/i';
     //String replace pattern for the collection name
     if (stristr($pattern, $collectionToken)) {
         $fingerprint = str_ireplace($collectionToken, $identifier, $pattern);
     } else {
         $fingerprint = $identifier . '-' . $pattern;
     }
     //Check for a date pattern and grab it if we need
     if (preg_match($dateTokenRegX, $fingerprint, $matches)) {
         $dateToken = $matches[0];
         $format = str_ireplace(array('[date:', ']'), '', $dateToken);
         //Extracts the date format to be used
         $formattedDate = date($format);
         //Create the formatted date
         $fingerprint = preg_replace($dateTokenRegX, $formattedDate, $fingerprint);
     }
     //Add the file extension
     $fingerprint .= '.' . $extension;
     return $fingerprint;
 }