Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up imports, rename ProcessorRegistry::get() to ProcessorRegistr…

…y::all()
  • Loading branch information...
commit c39dbdc8ed3a6b770c670da6a3f4c44cd3173195 1 parent 6baad15
@CHH authored
View
2  lib/Pipe/BundledAsset.php
@@ -9,7 +9,7 @@ function getBody()
if (null === $this->body) {
$body = parent::getBody();
- $bundleProcessors = $this->environment->bundleProcessors->get($this->getContentType());
+ $bundleProcessors = $this->environment->bundleProcessors->all($this->getContentType());
$context = new Context($this->environment);
$this->body = $context->evaluate($this->path, array(
View
65 lib/Pipe/Environment.php
@@ -2,12 +2,10 @@
namespace Pipe;
-use Pipe\Util\ProcessorRegistry,
- MetaTemplate\Template,
- MetaTemplate\Util\EngineRegistry,
- CHH\FileUtils\Path,
- CHH\FileUtils\PathInfo,
- CHH\FileUtils\PathStack;
+use Pipe\Util\ProcessorRegistry;
+use MetaTemplate\Template;
+use MetaTemplate\Util\EngineRegistry;
+use CHH\FileUtils;
class Environment implements \ArrayAccess
{
@@ -45,7 +43,7 @@ class Environment implements \ArrayAccess
function __construct($root = null)
{
$this->root = $root;
- $this->loadPaths = new Pathstack($this->root);
+ $this->loadPaths = new FileUtils\Pathstack($this->root);
$this->engines = Template::getEngines();
@@ -103,9 +101,24 @@ function appendPath($path)
return $this;
}
+ /**
+ * Finds the logical path in the stack of load paths
+ * and returns the Asset.
+ *
+ * Example:
+ *
+ * <?php
+ * // Get the bundled application.js
+ * $asset = $env->find('application.js', ['bundled' => true]);
+ *
+ * @param string $logicalPath Path relative to the load path.
+ * @param array $options
+ *
+ * @return Asset
+ */
function find($logicalPath, $options = array())
{
- $path = new PathInfo($logicalPath);
+ $path = new FileUtils\PathInfo($logicalPath);
if ($path->isAbsolute()) {
$realPath = $logicalPath;
@@ -130,6 +143,14 @@ function find($logicalPath, $options = array())
return $asset;
}
+ /**
+ * Set the JS compressor
+ *
+ * Adds the compressor class as bundle processor for JavaScript files.
+ * See $compressors for all available compressors.
+ *
+ * @param string $compressor Identifier of the compressor
+ */
function setJsCompressor($compressor)
{
if (!isset($this->compressors[$compressor])) {
@@ -146,6 +167,14 @@ function setJsCompressor($compressor)
$this->bundleProcessors->register($js, $this->compressors[$compressor]);
}
+ /**
+ * Set the CSS compressor
+ *
+ * Adds the compressor class as bundle processor for CSS files.
+ * See $compressors for all available compressors.
+ *
+ * @param string $compressor Identifier of the compressor
+ */
function setCssCompressor($compressor)
{
if (!isset($this->compressors[$compressor])) {
@@ -162,16 +191,24 @@ function setCssCompressor($compressor)
$this->bundleProcessors->register($css, $this->compressors[$compressor]);
}
+ /**
+ * Returns the content type for the extension, .e.g. "application/javascript"
+ * for ".js".
+ *
+ * @param string $extension
+ * @return string
+ */
function contentType($extension)
{
- return @$this->contentTypes[Path::normalizeExtension($extension)];
+ return @$this->contentTypes[FileUtils\Path::normalizeExtension($extension)];
}
- # Sugar for find().
- #
- # logicalPath - The path relative to the virtual file system.
- #
- # Returns an Asset.
+ /**
+ * Sugar for find()
+ *
+ * @param string $logicalPath
+ * @return \Pipe\Asset
+ */
function offsetGet($logicalPath)
{
return $this->find($logicalPath);
View
4 lib/Pipe/ProcessedAsset.php
@@ -62,9 +62,9 @@ function getProcessors()
$contentType = $this->getContentType();
return array_merge(
- $this->environment->preProcessors->get($contentType),
+ $this->environment->preProcessors->all($contentType),
array_reverse($this->getEngines()),
- $this->environment->postProcessors->get($contentType)
+ $this->environment->postProcessors->all($contentType)
);
}
}
View
9 lib/Pipe/Util/ProcessorRegistry.php
@@ -4,6 +4,7 @@
class ProcessorRegistry
{
+ /** @var array Engines per MIME type */
protected $processors = array();
function prepend($mimeType, $processor)
@@ -58,7 +59,13 @@ function clear()
$this->processors = array();
}
- function get($mimeType)
+ /**
+ * Returns all processor classes for the MIME type.
+ *
+ * @param string $mimeType
+ * @return array
+ */
+ function all($mimeType)
{
if (empty($this->processors[$mimeType])) {
return array();
Please sign in to comment.
Something went wrong with that request. Please try again.