mirror of
https://github.com/there4/markdown-resume.git
synced 2024-12-03 08:59:35 -05:00
Initial commit of Markdown Resume
This includes several vendor libraries: Assetic, LessPHP, Mustache, SmartyPants, Markdown
This commit is contained in:
163
vendor/Assetic/Asset/AssetCache.php
vendored
Executable file
163
vendor/Assetic/Asset/AssetCache.php
vendored
Executable file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Cache\CacheInterface;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Caches an asset to avoid the cost of loading and dumping.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCache implements AssetInterface
|
||||
{
|
||||
private $asset;
|
||||
private $cache;
|
||||
|
||||
public function __construct(AssetInterface $asset, CacheInterface $cache)
|
||||
{
|
||||
$this->asset = $asset;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->asset->ensureFilter($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->asset->getFilters();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->asset->clearFilters();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$cacheKey = self::getCacheKey($this->asset, $additionalFilter, 'load');
|
||||
if ($this->cache->has($cacheKey)) {
|
||||
$this->asset->setContent($this->cache->get($cacheKey));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->asset->load($additionalFilter);
|
||||
$this->cache->set($cacheKey, $this->asset->getContent());
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$cacheKey = self::getCacheKey($this->asset, $additionalFilter, 'dump');
|
||||
if ($this->cache->has($cacheKey)) {
|
||||
return $this->cache->get($cacheKey);
|
||||
}
|
||||
|
||||
$content = $this->asset->dump($additionalFilter);
|
||||
$this->cache->set($cacheKey, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->asset->getContent();
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->asset->setContent($content);
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->asset->getSourceRoot();
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->asset->getSourcePath();
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->asset->getTargetPath();
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->asset->setTargetPath($targetPath);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->asset->getLastModified();
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->asset->getVars();
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->asset->setValues($values);
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->asset->getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cache key for the current asset.
|
||||
*
|
||||
* The key is composed of everything but an asset's content:
|
||||
*
|
||||
* * source root
|
||||
* * source path
|
||||
* * target url
|
||||
* * last modified
|
||||
* * filters
|
||||
*
|
||||
* @param AssetInterface $asset The asset
|
||||
* @param FilterInterface $additionalFilter Any additional filter being applied
|
||||
* @param string $salt Salt for the key
|
||||
*
|
||||
* @return string A key for identifying the current asset
|
||||
*/
|
||||
static private function getCacheKey(AssetInterface $asset, FilterInterface $additionalFilter = null, $salt = '')
|
||||
{
|
||||
if ($additionalFilter) {
|
||||
$asset = clone $asset;
|
||||
$asset->ensureFilter($additionalFilter);
|
||||
}
|
||||
|
||||
$cacheKey = $asset->getSourceRoot();
|
||||
$cacheKey .= $asset->getSourcePath();
|
||||
$cacheKey .= $asset->getTargetPath();
|
||||
$cacheKey .= $asset->getLastModified();
|
||||
|
||||
foreach ($asset->getFilters() as $filter) {
|
||||
$cacheKey .= serialize($filter);
|
||||
}
|
||||
|
||||
if ($values = $asset->getValues()) {
|
||||
asort($values);
|
||||
$cacheKey .= serialize($values);
|
||||
}
|
||||
|
||||
return md5($cacheKey.$salt);
|
||||
}
|
||||
}
|
||||
217
vendor/Assetic/Asset/AssetCollection.php
vendored
Executable file
217
vendor/Assetic/Asset/AssetCollection.php
vendored
Executable file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Asset\Iterator\AssetCollectionFilterIterator;
|
||||
use Assetic\Asset\Iterator\AssetCollectionIterator;
|
||||
use Assetic\Filter\FilterCollection;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A collection of assets.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollection implements \IteratorAggregate, AssetCollectionInterface
|
||||
{
|
||||
private $assets;
|
||||
private $filters;
|
||||
private $sourceRoot;
|
||||
private $targetPath;
|
||||
private $content;
|
||||
private $clones;
|
||||
private $vars;
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $assets Assets for the current collection
|
||||
* @param array $filters Filters for the current collection
|
||||
* @param string $sourceRoot The root directory
|
||||
*/
|
||||
public function __construct($assets = array(), $filters = array(), $sourceRoot = null, array $vars = array())
|
||||
{
|
||||
$this->assets = array();
|
||||
foreach ($assets as $asset) {
|
||||
$this->add($asset);
|
||||
}
|
||||
|
||||
$this->filters = new FilterCollection($filters);
|
||||
$this->sourceRoot = $sourceRoot;
|
||||
$this->clones = new \SplObjectStorage();
|
||||
$this->vars = $vars;
|
||||
$this->values = array();
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->assets;
|
||||
}
|
||||
|
||||
public function add(AssetInterface $asset)
|
||||
{
|
||||
$this->assets[] = $asset;
|
||||
}
|
||||
|
||||
public function removeLeaf(AssetInterface $needle, $graceful = false)
|
||||
{
|
||||
foreach ($this->assets as $i => $asset) {
|
||||
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
|
||||
if (in_array($needle, array($asset, $clone), true)) {
|
||||
unset($this->clones[$asset], $this->assets[$i]);
|
||||
return true;
|
||||
} elseif ($asset instanceof AssetCollectionInterface && $asset->removeLeaf($needle, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($graceful) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Leaf not found.');
|
||||
}
|
||||
|
||||
public function replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful = false)
|
||||
{
|
||||
foreach ($this->assets as $i => $asset) {
|
||||
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
|
||||
if (in_array($needle, array($asset, $clone), true)) {
|
||||
unset($this->clones[$asset]);
|
||||
$this->assets[$i] = $replacement;
|
||||
return true;
|
||||
} elseif ($asset instanceof AssetCollectionInterface && $asset->replaceLeaf($needle, $replacement, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($graceful) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Leaf not found.');
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters->ensure($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters->all();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters->clear();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
// loop through leaves and load each asset
|
||||
$parts = array();
|
||||
foreach ($this as $asset) {
|
||||
$asset->load($additionalFilter);
|
||||
$parts[] = $asset->getContent();
|
||||
}
|
||||
|
||||
$this->content = implode("\n", $parts);
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
// loop through leaves and dump each asset
|
||||
$parts = array();
|
||||
foreach ($this as $asset) {
|
||||
$parts[] = $asset->dump($additionalFilter);
|
||||
}
|
||||
|
||||
return implode("\n", $parts);
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->sourceRoot;
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->targetPath;
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->targetPath = $targetPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest last-modified value of all assets in the current collection.
|
||||
*
|
||||
* @return integer|null A UNIX timestamp
|
||||
*/
|
||||
public function getLastModified()
|
||||
{
|
||||
if (!count($this->assets)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mapper = function (AssetInterface $asset)
|
||||
{
|
||||
return $asset->getLastModified();
|
||||
};
|
||||
|
||||
return max(array_map($mapper, $this->assets));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for looping recursively over unique leaves.
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \RecursiveIteratorIterator(new AssetCollectionFilterIterator(new AssetCollectionIterator($this, $this->clones)));
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
|
||||
foreach ($this as $asset) {
|
||||
$asset->setValues(array_intersect_key($values, array_flip($asset->getVars())));
|
||||
}
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
}
|
||||
53
vendor/Assetic/Asset/AssetCollectionInterface.php
vendored
Executable file
53
vendor/Assetic/Asset/AssetCollectionInterface.php
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
/**
|
||||
* An asset collection.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface AssetCollectionInterface extends AssetInterface, \Traversable
|
||||
{
|
||||
/**
|
||||
* Returns all child assets.
|
||||
*
|
||||
* @return array An array of AssetInterface objects
|
||||
*/
|
||||
function all();
|
||||
|
||||
/**
|
||||
* Adds an asset to the current collection.
|
||||
*
|
||||
* @param AssetInterface $asset An asset
|
||||
*/
|
||||
function add(AssetInterface $asset);
|
||||
|
||||
/**
|
||||
* Removes a leaf.
|
||||
*
|
||||
* @param AssetInterface $needle The leaf to remove
|
||||
*
|
||||
* @throws InvalidArgumentException If the asset cannot be found
|
||||
*/
|
||||
function removeLeaf(AssetInterface $leaf);
|
||||
|
||||
/**
|
||||
* Replaces an existing leaf with a new one.
|
||||
*
|
||||
* @param AssetInterface $needle The current asset to replace
|
||||
* @param AssetInterface $replacement The new asset
|
||||
*
|
||||
* @throws InvalidArgumentException If the asset cannot be found
|
||||
*/
|
||||
function replaceLeaf(AssetInterface $needle, AssetInterface $replacement);
|
||||
}
|
||||
156
vendor/Assetic/Asset/AssetInterface.php
vendored
Executable file
156
vendor/Assetic/Asset/AssetInterface.php
vendored
Executable file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* An asset has a mutable URL and content and can be loaded and dumped.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface AssetInterface
|
||||
{
|
||||
/**
|
||||
* Ensures the current asset includes the supplied filter.
|
||||
*
|
||||
* @param FilterInterface $filter A filter
|
||||
*/
|
||||
function ensureFilter(FilterInterface $filter);
|
||||
|
||||
/**
|
||||
* Returns an array of filters currently applied.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
function getFilters();
|
||||
|
||||
/**
|
||||
* Clears all filters from the current asset.
|
||||
*/
|
||||
function clearFilters();
|
||||
|
||||
/**
|
||||
* Loads the asset into memory and applies load filters.
|
||||
*
|
||||
* You may provide an additional filter to apply during load.
|
||||
*
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*/
|
||||
function load(FilterInterface $additionalFilter = null);
|
||||
|
||||
/**
|
||||
* Applies dump filters and returns the asset as a string.
|
||||
*
|
||||
* You may provide an additional filter to apply during dump.
|
||||
*
|
||||
* Dumping an asset should not change its state.
|
||||
*
|
||||
* If the current asset has not been loaded yet, it should be
|
||||
* automatically loaded at this time.
|
||||
*
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*
|
||||
* @return string The filtered content of the current asset
|
||||
*/
|
||||
function dump(FilterInterface $additionalFilter = null);
|
||||
|
||||
/**
|
||||
* Returns the loaded content of the current asset.
|
||||
*
|
||||
* @return string The content
|
||||
*/
|
||||
function getContent();
|
||||
|
||||
/**
|
||||
* Sets the content of the current asset.
|
||||
*
|
||||
* Filters can use this method to change the content of the asset.
|
||||
*
|
||||
* @param string $content The asset content
|
||||
*/
|
||||
function setContent($content);
|
||||
|
||||
/**
|
||||
* Returns an absolute path or URL to the source asset's root directory.
|
||||
*
|
||||
* This value should be an absolute path to a directory in the filesystem,
|
||||
* an absolute URL with no path, or null.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* * '/path/to/web'
|
||||
* * 'http://example.com'
|
||||
* * null
|
||||
*
|
||||
* @return string|null The asset's root
|
||||
*/
|
||||
function getSourceRoot();
|
||||
|
||||
/**
|
||||
* Returns the relative path for the source asset.
|
||||
*
|
||||
* This value can be combined with the asset's source root (if both are
|
||||
* non-null) to get something compatible with file_get_contents().
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* * 'js/main.js'
|
||||
* * 'main.js'
|
||||
* * null
|
||||
*
|
||||
* @return string|null The source asset path
|
||||
*/
|
||||
function getSourcePath();
|
||||
|
||||
/**
|
||||
* Returns the URL for the current asset.
|
||||
*
|
||||
* @return string|null A web URL where the asset will be dumped
|
||||
*/
|
||||
function getTargetPath();
|
||||
|
||||
/**
|
||||
* Sets the URL for the current asset.
|
||||
*
|
||||
* @param string $targetPath A web URL where the asset will be dumped
|
||||
*/
|
||||
function setTargetPath($targetPath);
|
||||
|
||||
/**
|
||||
* Returns the time the current asset was last modified.
|
||||
*
|
||||
* @return integer|null A UNIX timestamp
|
||||
*/
|
||||
function getLastModified();
|
||||
|
||||
/**
|
||||
* Returns an array of variable names for this asset.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getVars();
|
||||
|
||||
/**
|
||||
* Sets the values for the asset's variables.
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
function setValues(array $values);
|
||||
|
||||
/**
|
||||
* Returns the current values for this asset.
|
||||
*
|
||||
* @return array an array of strings
|
||||
*/
|
||||
function getValues();
|
||||
}
|
||||
134
vendor/Assetic/Asset/AssetReference.php
vendored
Executable file
134
vendor/Assetic/Asset/AssetReference.php
vendored
Executable file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\Filter\FilterCollection;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A reference to an asset in the asset manager.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetReference implements AssetInterface
|
||||
{
|
||||
private $am;
|
||||
private $name;
|
||||
private $filters = array();
|
||||
|
||||
public function __construct(AssetManager $am, $name)
|
||||
{
|
||||
$this->am = $am;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters[] = $filter;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters = array();
|
||||
$this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__, array($additionalFilter));
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__, array($additionalFilter));
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($content));
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($targetPath));
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($values));
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
private function callAsset($method, $arguments = array())
|
||||
{
|
||||
$asset = $this->am->get($this->name);
|
||||
|
||||
return call_user_func_array(array($asset, $method), $arguments);
|
||||
}
|
||||
|
||||
private function flushFilters()
|
||||
{
|
||||
$asset = $this->am->get($this->name);
|
||||
|
||||
while ($filter = array_shift($this->filters)) {
|
||||
$asset->ensureFilter($filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
169
vendor/Assetic/Asset/BaseAsset.php
vendored
Executable file
169
vendor/Assetic/Asset/BaseAsset.php
vendored
Executable file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterCollection;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A base abstract asset.
|
||||
*
|
||||
* The methods load() and getLastModified() are left undefined, although a
|
||||
* reusable doLoad() method is available to child classes.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
abstract class BaseAsset implements AssetInterface
|
||||
{
|
||||
private $filters;
|
||||
private $sourceRoot;
|
||||
private $sourcePath;
|
||||
private $targetPath;
|
||||
private $content;
|
||||
private $loaded;
|
||||
private $vars;
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $filters Filters for the asset
|
||||
*/
|
||||
public function __construct($filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
|
||||
{
|
||||
$this->filters = new FilterCollection($filters);
|
||||
$this->sourceRoot = $sourceRoot;
|
||||
$this->sourcePath = $sourcePath;
|
||||
$this->vars = $vars;
|
||||
$this->values = array();
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->filters = clone $this->filters;
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters->ensure($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters->all();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates asset loading logic.
|
||||
*
|
||||
* @param string $content The asset content
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*/
|
||||
protected function doLoad($content, FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$filter = clone $this->filters;
|
||||
if ($additionalFilter) {
|
||||
$filter->ensure($additionalFilter);
|
||||
}
|
||||
|
||||
$asset = clone $this;
|
||||
$asset->setContent($content);
|
||||
|
||||
$filter->filterLoad($asset);
|
||||
$this->content = $asset->getContent();
|
||||
|
||||
$this->loaded = true;
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
$filter = clone $this->filters;
|
||||
if ($additionalFilter) {
|
||||
$filter->ensure($additionalFilter);
|
||||
}
|
||||
|
||||
$asset = clone $this;
|
||||
$filter->filterDump($asset);
|
||||
|
||||
return $asset->getContent();
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->sourceRoot;
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->sourcePath;
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->targetPath;
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
if ($this->vars) {
|
||||
foreach ($this->vars as $var) {
|
||||
if (false === strpos($targetPath, $var)) {
|
||||
throw new \RuntimeException(sprintf('The asset target path "%s" must contain the variable "{%s}".', $targetPath, $var));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->targetPath = $targetPath;
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
foreach ($values as $var => $v) {
|
||||
if (!in_array($var, $this->vars, true)) {
|
||||
throw new \InvalidArgumentException(sprintf('The asset with source path "%s" has no variable named "%s".', $this->sourcePath, $var));
|
||||
}
|
||||
}
|
||||
|
||||
$this->values = $values;
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
}
|
||||
78
vendor/Assetic/Asset/FileAsset.php
vendored
Executable file
78
vendor/Assetic/Asset/FileAsset.php
vendored
Executable file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Util\PathUtils;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Represents an asset loaded from a file.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FileAsset extends BaseAsset
|
||||
{
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* 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, array $vars = array())
|
||||
{
|
||||
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, $vars);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$source = PathUtils::resolvePath($this->source, $this->getVars(),
|
||||
$this->getValues());
|
||||
|
||||
if (!is_file($source)) {
|
||||
throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
|
||||
}
|
||||
|
||||
$this->doLoad(file_get_contents($source), $additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
$source = PathUtils::resolvePath($this->source, $this->getVars(),
|
||||
$this->getValues());
|
||||
|
||||
if (!is_file($source)) {
|
||||
throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
|
||||
}
|
||||
return filemtime($source);
|
||||
}
|
||||
}
|
||||
111
vendor/Assetic/Asset/GlobAsset.php
vendored
Executable file
111
vendor/Assetic/Asset/GlobAsset.php
vendored
Executable file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Util\PathUtils;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A collection of assets loaded by glob.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class GlobAsset extends AssetCollection
|
||||
{
|
||||
private $globs;
|
||||
private $initialized;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|array $globs A single glob path or array of paths
|
||||
* @param array $filters An array of filters
|
||||
* @param string $root The root directory
|
||||
*/
|
||||
public function __construct($globs, $filters = array(), $root = null, array $vars = array())
|
||||
{
|
||||
$this->globs = (array) $globs;
|
||||
$this->initialized = false;
|
||||
|
||||
parent::__construct(array(), $filters, $root, $vars);
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::all();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
parent::load($additionalFilter);
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::dump($additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::getLastModified();
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::getIterator();
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
parent::setValues($values);
|
||||
$this->initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the collection based on the glob(s) passed in.
|
||||
*/
|
||||
private function initialize()
|
||||
{
|
||||
foreach ($this->globs as $glob) {
|
||||
$glob = PathUtils::resolvePath($glob, $this->getVars(), $this->getValues());
|
||||
|
||||
if (false !== $paths = glob($glob)) {
|
||||
foreach ($paths as $path) {
|
||||
$this->add(new FileAsset($path, array(), $this->getSourceRoot()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialized = true;
|
||||
}
|
||||
}
|
||||
79
vendor/Assetic/Asset/HttpAsset.php
vendored
Executable file
79
vendor/Assetic/Asset/HttpAsset.php
vendored
Executable file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Util\PathUtils;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Represents an asset loaded via an HTTP request.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class HttpAsset extends BaseAsset
|
||||
{
|
||||
private $sourceUrl;
|
||||
private $ignoreErrors;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $sourceUrl The source URL
|
||||
* @param array $filters An array of filters
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (false === $content = @file_get_contents(PathUtils::resolvePath(
|
||||
$this->sourceUrl, $this->getVars(), $this->getValues()))) {
|
||||
if ($this->ignoreErrors) {
|
||||
return;
|
||||
} else {
|
||||
throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
|
||||
}
|
||||
}
|
||||
|
||||
$this->doLoad($content, $additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(array('http' => array('method' => 'HEAD'))))) {
|
||||
foreach ($http_response_header as $header) {
|
||||
if (0 === stripos($header, 'Last-Modified: ')) {
|
||||
list(, $mtime) = explode(':', $header, 2);
|
||||
|
||||
return strtotime(trim($mtime));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
vendor/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php
vendored
Executable file
84
vendor/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php
vendored
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset\Iterator;
|
||||
|
||||
/**
|
||||
* Asset collection filter iterator.
|
||||
*
|
||||
* The filter iterator is responsible for de-duplication of leaf assets based
|
||||
* on both strict equality and source URL.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollectionFilterIterator extends \RecursiveFilterIterator
|
||||
{
|
||||
private $visited;
|
||||
private $sources;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param AssetCollectionIterator $iterator The inner iterator
|
||||
* @param array $visited An array of visited asset objects
|
||||
* @param array $sources An array of visited source strings
|
||||
*/
|
||||
public function __construct(AssetCollectionIterator $iterator, array $visited = array(), array $sources = array())
|
||||
{
|
||||
parent::__construct($iterator);
|
||||
|
||||
$this->visited = $visited;
|
||||
$this->sources = $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current asset is a duplicate.
|
||||
*
|
||||
* De-duplication is performed based on either strict equality or by
|
||||
* matching sources.
|
||||
*
|
||||
* @return Boolean Returns true if we have not seen this asset yet
|
||||
*/
|
||||
public function accept()
|
||||
{
|
||||
$asset = $this->getInnerIterator()->current(true);
|
||||
$duplicate = false;
|
||||
|
||||
// check strict equality
|
||||
if (in_array($asset, $this->visited, true)) {
|
||||
$duplicate = true;
|
||||
} else {
|
||||
$this->visited[] = $asset;
|
||||
}
|
||||
|
||||
// check source
|
||||
$sourceRoot = $asset->getSourceRoot();
|
||||
$sourcePath = $asset->getSourcePath();
|
||||
if ($sourceRoot && $sourcePath) {
|
||||
$source = $sourceRoot.'/'.$sourcePath;
|
||||
if (in_array($source, $this->sources)) {
|
||||
$duplicate = true;
|
||||
} else {
|
||||
$this->sources[] = $source;
|
||||
}
|
||||
}
|
||||
|
||||
return !$duplicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes visited objects and source URLs to the child iterator.
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return new self($this->getInnerIterator()->getChildren(), $this->visited, $this->sources);
|
||||
}
|
||||
}
|
||||
109
vendor/Assetic/Asset/Iterator/AssetCollectionIterator.php
vendored
Executable file
109
vendor/Assetic/Asset/Iterator/AssetCollectionIterator.php
vendored
Executable file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset\Iterator;
|
||||
|
||||
use Assetic\Asset\AssetCollectionInterface;
|
||||
|
||||
/**
|
||||
* Iterates over an asset collection.
|
||||
*
|
||||
* The iterator is responsible for cascading filters and target URL patterns
|
||||
* from parent to child assets.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollectionIterator implements \RecursiveIterator
|
||||
{
|
||||
private $assets;
|
||||
private $filters;
|
||||
private $output;
|
||||
private $clones;
|
||||
|
||||
public function __construct(AssetCollectionInterface $coll, \SplObjectStorage $clones)
|
||||
{
|
||||
$this->assets = $coll->all();
|
||||
$this->filters = $coll->getFilters();
|
||||
$this->output = $coll->getTargetPath();
|
||||
$this->clones = $clones;
|
||||
|
||||
if (false === $pos = strpos($this->output, '.')) {
|
||||
$this->output .= '_*';
|
||||
} else {
|
||||
$this->output = substr($this->output, 0, $pos).'_*'.substr($this->output, $pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the current asset with filters and a target URL applied.
|
||||
*
|
||||
* @param Boolean $raw Returns the unmodified asset if true
|
||||
*/
|
||||
public function current($raw = false)
|
||||
{
|
||||
$asset = current($this->assets);
|
||||
|
||||
if ($raw) {
|
||||
return $asset;
|
||||
}
|
||||
|
||||
// clone once
|
||||
if (!isset($this->clones[$asset])) {
|
||||
$clone = $this->clones[$asset] = clone $asset;
|
||||
|
||||
// generate a target path based on asset name
|
||||
$name = sprintf('%s_%d', pathinfo($asset->getSourcePath(), PATHINFO_FILENAME) ?: 'part', $this->key() + 1);
|
||||
$clone->setTargetPath(str_replace('*', $name, $this->output));
|
||||
} else {
|
||||
$clone = $this->clones[$asset];
|
||||
}
|
||||
|
||||
// cascade filters
|
||||
foreach ($this->filters as $filter) {
|
||||
$clone->ensureFilter($filter);
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->assets);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->assets);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->assets);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return false !== current($this->assets);
|
||||
}
|
||||
|
||||
public function hasChildren()
|
||||
{
|
||||
return current($this->assets) instanceof AssetCollectionInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses current()
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return new self($this->current(), $this->clones);
|
||||
}
|
||||
}
|
||||
55
vendor/Assetic/Asset/StringAsset.php
vendored
Executable file
55
vendor/Assetic/Asset/StringAsset.php
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Represents a string asset.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class StringAsset extends BaseAsset
|
||||
{
|
||||
private $content;
|
||||
private $lastModified;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->doLoad($this->content, $additionalFilter);
|
||||
}
|
||||
|
||||
public function setLastModified($lastModified)
|
||||
{
|
||||
$this->lastModified = $lastModified;
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user