MiniAsset\Factory::writer PHP Method

writer() public method

Create an AssetWriter
public writer ( string $tmpPath = '' ) : MiniAsset\AssetWriter
$tmpPath string The path where the build timestamp lookup should be stored.
return MiniAsset\AssetWriter
    public function writer($tmpPath = '')
    {
        if (!$tmpPath) {
            $tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR;
        }
        $timestamp = ['js' => $this->config->get('js.timestamp'), 'css' => $this->config->get('css.timestamp')];
        $writer = new AssetWriter($timestamp, $tmpPath, $this->config->theme());
        $writer->configTimestamp($this->config->modifiedTime());
        $writer->filterRegistry($this->filterRegistry());
        return $writer;
    }

Usage Example

Example #1
0
 /**
  * Generate and save the cached file for a build target.
  *
  * @param \MiniAsset\Factory $factory The factory class.
  * @param \MiniAsset\AssetTarget $build The build target.
  * @return void
  */
 protected function _buildTarget($factory, $build)
 {
     $writer = $factory->writer();
     $compiler = $factory->cachedCompiler();
     $name = $writer->buildFileName($build);
     if ($writer->isFresh($build) && !$this->cli->arguments->defined('force')) {
         $this->verbose('<light_blue>Skip building</light_blue> ' . $name . ' existing file is still fresh.', 'S');
         return;
     }
     $writer->invalidate($build);
     $name = $writer->buildFileName($build);
     try {
         $contents = $compiler->generate($build);
         $writer->write($build, $contents);
         $this->verbose('<green>Saved file</green> for ' . $name, '.');
     } catch (Exception $e) {
         $this->cli->err('<red>Error:</red> ' . $e->getMessage());
     }
 }
All Usage Examples Of MiniAsset\Factory::writer