/** * Constructor. * * @param string $sourceUrl The source URL * @param array $filters An array of filters * @param Boolean $ignoreErrors * @param array $vars * * @throws \InvalidArgumentException If the first argument is not an URL */ public function __construct($sourceUrl, $filters = array(), $ignoreErrors = false, array $vars = array()) { if (0 === strpos($sourceUrl, '//')) { $sourceUrl = 'http:' . $sourceUrl; } elseif (false === strpos($sourceUrl, '://')) { throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl)); } $this->sourceUrl = $sourceUrl; $this->ignoreErrors = $ignoreErrors; list($scheme, $url) = explode('://', $sourceUrl, 2); list($host, $path) = explode('/', $url, 2); parent::__construct($filters, $scheme . '://' . $host, $path, $vars); }
/** * Constructor. * * @param string $source An absolute path * @param array $filters An array of filters * @param string $sourceRoot The source asset root directory * @param string $sourcePath The source asset path * * @throws InvalidArgumentException If the supplied root doesn't match the source when guessing the path */ public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null) { if (null === $sourceRoot) { $sourceRoot = dirname($source); if (null === $sourcePath) { $sourcePath = basename($source); } } elseif (null === $sourcePath) { if (0 !== strpos($source, $sourceRoot)) { throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot)); } $sourcePath = substr($source, strlen($sourceRoot) + 1); } $this->source = $source; parent::__construct($filters, $sourceRoot, $sourcePath); }
/** * Constructor. * * @param string $content The content of the asset * @param array $filters Filters for the asset * @param string $sourceRoot The source asset root directory * @param string $sourcePath The source asset path */ public function __construct($content, $filters = array(), $sourceRoot = null, $sourcePath = null) { $this->content = $content; parent::__construct($filters, $sourceRoot, $sourcePath); }
/** * Constructor. * * @param string $content The content of the asset * @param array $filters Filters for the asset * @param string $sourceUrl The source URL */ public function __construct($content, $filters = array(), $sourceUrl = null) { $this->originalContent = $content; parent::__construct($filters, $sourceUrl); }
/** * Creates the asset. * * You can pass asset variables that can later be set with * {@link setValues()}. However, the variable values won't have any effect * on the loaded resource. * * @param BodyResource $resource The underlying Puli resource. * @param string[] $vars The asset variables. */ public function __construct(BodyResource $resource, array $vars = array()) { parent::__construct(array(), null, $resource->getPath(), $vars); $this->resource = $resource; }
/** * Constructor. * * @param string $path The absolute path to the asset * @param array $filters Filters for the asset * @param string $sourceUrl The source URL */ public function __construct($path, $filters = array(), $sourceUrl = null) { $this->path = $path; parent::__construct($filters, $sourceUrl); }
/** * Constructor. * * @param array $content The array of assets to be merged * @param array $filters Filters for the asset * @param string $sourceRoot The source asset root directory * @param string $sourcePath The source asset path */ public function __construct(array $content = array(), $filters = array(), $sourceRoot = null, $sourcePath = null) { parent::__construct($filters, $sourceRoot, $sourcePath); $this->processContent($content); }
/** * Creates the asset. * * You can pass asset variables that occur in the path. You can later set * the variables by calling {@link setValues()}. * * @param ResourceRepository $repo The resource repository. * @param string $path The Puli path. * @param array $vars The asset variables. */ public function __construct(ResourceRepository $repo, $path, array $vars = array()) { parent::__construct(array(), null, $path, $vars); $this->repo = $repo; $this->path = $path; }
public function writeAsset(BaseAsset $asset, $path = null, $prefix = null) { if (null === $path) { $path = $this->getOutputDir() . DIRECTORY_SEPARATOR . basename($asset->getSourcePath()); } if (null !== $prefix) { $path = dirname($path) . DIRECTORY_SEPARATOR . $prefix . basename($path); } if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) { throw new \RuntimeException('Unable to create directory ' . $dir); } if (false === @file_put_contents($path, $asset->dump())) { throw new \RuntimeException('Unable to write file ' . $path); } return $path; }