diff --git a/composer.json b/composer.json index 64519e00a..42b3e2513 100644 --- a/composer.json +++ b/composer.json @@ -34,18 +34,20 @@ "ext-openssl": "*", "ext-PDO": "*", "ext-zip": "*", + + "assetic/framework": "~3.0", "doctrine/dbal": "^2.6", "erusev/parsedown-extra": "~0.7", - "linkorb/jsmin-php": "~1.0", - "wikimedia/less.php": "~3.0", - "scssphp/scssphp": "~1.0", - "symfony/yaml": "^5.1", - "twig/twig": "~3.0", - "league/csv": "~9.1", - "nesbot/carbon": "^2.0", "laravel/framework": "~9.0", "laravel/tinker": "^2.7", - "nikic/php-parser": "^4.10" + "league/csv": "~9.1", + "nesbot/carbon": "^2.0", + "nikic/php-parser": "^4.10", + "scssphp/scssphp": "~1.0", + "symfony/yaml": "^6.0", + "twig/twig": "~3.0", + "wikimedia/less.php": "~3.0", + "wikimedia/minify": "~2.2" }, "require-dev": { "phpunit/phpunit": "^9.5.8", diff --git a/src/Assetic/Asset/AssetCache.php b/src/Assetic/Asset/AssetCache.php deleted file mode 100644 index 27051c7c5..000000000 --- a/src/Assetic/Asset/AssetCache.php +++ /dev/null @@ -1,172 +0,0 @@ - - */ -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 getSourceDirectory() - { - return $this->asset->getSourceDirectory(); - } - - 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 - */ - private static 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) { - if ($filter instanceof HashableInterface) { - $cacheKey .= $filter->hash(); - } else { - $cacheKey .= serialize($filter); - } - } - - if ($values = $asset->getValues()) { - asort($values); - $cacheKey .= serialize($values); - } - - return md5($cacheKey.$salt); - } -} diff --git a/src/Assetic/Asset/AssetCollection.php b/src/Assetic/Asset/AssetCollection.php deleted file mode 100644 index ff9191099..000000000 --- a/src/Assetic/Asset/AssetCollection.php +++ /dev/null @@ -1,237 +0,0 @@ - - */ -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 - * @param array $vars - */ - 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 __clone() - { - $this->filters = clone $this->filters; - $this->clones = new \SplObjectStorage(); - } - - 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; - } - - if ($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; - } - - if ($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(); - $this->clones = new \SplObjectStorage(); - } - - 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 getSourceDirectory() - { - } - - 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; - } - - $mtime = 0; - foreach ($this as $asset) { - $assetMtime = $asset->getLastModified(); - if ($assetMtime > $mtime) { - $mtime = $assetMtime; - } - } - - return $mtime; - } - - /** - * Returns an iterator for looping recursively over unique leaves. - */ - public function getIterator(): Traversable - { - 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; - } -} diff --git a/src/Assetic/Asset/AssetCollectionInterface.php b/src/Assetic/Asset/AssetCollectionInterface.php deleted file mode 100644 index 0bdb5bb5d..000000000 --- a/src/Assetic/Asset/AssetCollectionInterface.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ -interface AssetCollectionInterface extends AssetInterface, \Traversable -{ - /** - * Returns all child assets. - * - * @return array An array of AssetInterface objects - */ - public function all(); - - /** - * Adds an asset to the current collection. - * - * @param AssetInterface $asset An asset - */ - public function add(AssetInterface $asset); - - /** - * Removes a leaf. - * - * @param AssetInterface $leaf The leaf to remove - * @param Boolean $graceful Whether the failure should return false or throw an exception - * - * @return Boolean Whether the asset has been found - * - * @throws \InvalidArgumentException If the asset cannot be found - */ - public function removeLeaf(AssetInterface $leaf, $graceful = false); - - /** - * Replaces an existing leaf with a new one. - * - * @param AssetInterface $needle The current asset to replace - * @param AssetInterface $replacement The new asset - * @param Boolean $graceful Whether the failure should return false or throw an exception - * - * @return Boolean Whether the asset has been found - * - * @throws \InvalidArgumentException If the asset cannot be found - */ - public function replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful = false); -} diff --git a/src/Assetic/Asset/AssetInterface.php b/src/Assetic/Asset/AssetInterface.php deleted file mode 100644 index e6a364a2c..000000000 --- a/src/Assetic/Asset/AssetInterface.php +++ /dev/null @@ -1,164 +0,0 @@ - - */ -interface AssetInterface -{ - /** - * Ensures the current asset includes the supplied filter. - * - * @param FilterInterface $filter A filter - */ - public function ensureFilter(FilterInterface $filter); - - /** - * Returns an array of filters currently applied. - * - * @return array An array of filters - */ - public function getFilters(); - - /** - * Clears all filters from the current asset. - */ - public 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 - */ - public 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 - */ - public function dump(FilterInterface $additionalFilter = null); - - /** - * Returns the loaded content of the current asset. - * - * @return string The content - */ - public 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 - */ - public 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 - */ - public 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 - */ - public function getSourcePath(); - - /** - * Returns the asset's source directory. - * - * The source directory is the directory the asset was located in - * and can be used to resolve references relative to an asset. - * - * @return string|null The asset's source directory - */ - public function getSourceDirectory(); - - /** - * Returns the URL for the current asset. - * - * @return string|null A web URL where the asset will be dumped - */ - public function getTargetPath(); - - /** - * Sets the URL for the current asset. - * - * @param string $targetPath A web URL where the asset will be dumped - */ - public function setTargetPath($targetPath); - - /** - * Returns the time the current asset was last modified. - * - * @return integer|null A UNIX timestamp - */ - public function getLastModified(); - - /** - * Returns an array of variable names for this asset. - * - * @return array - */ - public function getVars(); - - /** - * Sets the values for the asset's variables. - * - * @param array $values - */ - public function setValues(array $values); - - /** - * Returns the current values for this asset. - * - * @return array an array of strings - */ - public function getValues(); -} diff --git a/src/Assetic/Asset/AssetReference.php b/src/Assetic/Asset/AssetReference.php deleted file mode 100644 index 07ecedb03..000000000 --- a/src/Assetic/Asset/AssetReference.php +++ /dev/null @@ -1,162 +0,0 @@ - - */ -class AssetReference implements AssetInterface -{ - private $am; - private $name; - private $filters = array(); - private $clone = false; - private $asset; - - public function __construct(AssetManager $am, $name) - { - $this->am = $am; - $this->name = $name; - } - - public function __clone() - { - $this->clone = true; - - if ($this->asset) { - $this->asset = clone $this->asset; - } - } - - 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 getSourceDirectory() - { - 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->resolve(); - - return call_user_func_array(array($asset, $method), $arguments); - } - - private function flushFilters() - { - $asset = $this->resolve(); - - while ($filter = array_shift($this->filters)) { - $asset->ensureFilter($filter); - } - } - - private function resolve() - { - if ($this->asset) { - return $this->asset; - } - - $asset = $this->am->get($this->name); - - if ($this->clone) { - $asset = $this->asset = clone $asset; - } - - return $asset; - } -} diff --git a/src/Assetic/Asset/BaseAsset.php b/src/Assetic/Asset/BaseAsset.php deleted file mode 100644 index 7d799e1b2..000000000 --- a/src/Assetic/Asset/BaseAsset.php +++ /dev/null @@ -1,179 +0,0 @@ - - */ -abstract class BaseAsset implements AssetInterface -{ - private $filters; - private $sourceRoot; - private $sourcePath; - private $sourceDir; - private $targetPath; - private $content; - private $loaded; - private $vars; - private $values; - - /** - * Constructor. - * - * @param array $filters Filters for the asset - * @param string $sourceRoot The root directory - * @param string $sourcePath The asset path - * @param array $vars - */ - public function __construct($filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array()) - { - $this->filters = new FilterCollection($filters); - $this->sourceRoot = $sourceRoot; - $this->sourcePath = $sourcePath; - if ($sourcePath && $sourceRoot) { - $this->sourceDir = dirname("$sourceRoot/$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 getSourceDirectory() - { - return $this->sourceDir; - } - - 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; - } -} diff --git a/src/Assetic/Asset/FileAsset.php b/src/Assetic/Asset/FileAsset.php deleted file mode 100644 index c26c5efa1..000000000 --- a/src/Assetic/Asset/FileAsset.php +++ /dev/null @@ -1,76 +0,0 @@ - - */ -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 - * @param array $vars - * - * @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 = VarUtils::resolve($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 = VarUtils::resolve($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); - } -} diff --git a/src/Assetic/Asset/GlobAsset.php b/src/Assetic/Asset/GlobAsset.php deleted file mode 100644 index 28e7f9d61..000000000 --- a/src/Assetic/Asset/GlobAsset.php +++ /dev/null @@ -1,114 +0,0 @@ - - */ -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 - * @param array $vars - */ - 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(): Traversable - { - 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 = VarUtils::resolve($glob, $this->getVars(), $this->getValues()); - - if (false !== $paths = glob($glob)) { - foreach ($paths as $path) { - if (is_file($path)) { - $asset = new FileAsset($path, array(), $this->getSourceRoot(), null, $this->getVars()); - $asset->setValues($this->getValues()); - $this->add($asset); - } - } - } - } - - $this->initialized = true; - } -} diff --git a/src/Assetic/Asset/HttpAsset.php b/src/Assetic/Asset/HttpAsset.php deleted file mode 100644 index fabfe453c..000000000 --- a/src/Assetic/Asset/HttpAsset.php +++ /dev/null @@ -1,77 +0,0 @@ - - */ -class HttpAsset extends BaseAsset -{ - private $sourceUrl; - private $ignoreErrors; - - /** - * 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); - } - - public function load(FilterInterface $additionalFilter = null) - { - $content = @file_get_contents( - VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues()) - ); - - if (false === $content && !$this->ignoreErrors) { - 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)); - } - } - } - } -} diff --git a/src/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php b/src/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php deleted file mode 100644 index c2ce7f7ae..000000000 --- a/src/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php +++ /dev/null @@ -1,82 +0,0 @@ - - */ -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); - } -} diff --git a/src/Assetic/Asset/Iterator/AssetCollectionIterator.php b/src/Assetic/Asset/Iterator/AssetCollectionIterator.php deleted file mode 100644 index faf6b1605..000000000 --- a/src/Assetic/Asset/Iterator/AssetCollectionIterator.php +++ /dev/null @@ -1,126 +0,0 @@ - - */ -class AssetCollectionIterator implements \RecursiveIterator -{ - private $assets; - private $filters; - private $vars; - private $output; - private $clones; - - public function __construct(AssetCollectionInterface $coll, \SplObjectStorage $clones) - { - $this->assets = $coll->all(); - $this->filters = $coll->getFilters(); - $this->vars = $coll->getVars(); - $this->output = $coll->getTargetPath(); - $this->clones = $clones; - - if (false === $pos = strrpos($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 - * - * @return \Assetic\Asset\AssetInterface - */ - 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); - - $name = $this->removeDuplicateVar($name); - - $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); - } - - private function removeDuplicateVar($name) - { - foreach ($this->vars as $var) { - $var = '{'.$var.'}'; - if (false !== strpos($name, $var) && false !== strpos($this->output, $var)) { - $name = str_replace($var, '', $name); - } - } - - return $name; - } -} diff --git a/src/Assetic/Asset/StringAsset.php b/src/Assetic/Asset/StringAsset.php deleted file mode 100644 index a047e2c1b..000000000 --- a/src/Assetic/Asset/StringAsset.php +++ /dev/null @@ -1,53 +0,0 @@ - - */ -class StringAsset extends BaseAsset -{ - private $string; - 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->string = $content; - - parent::__construct($filters, $sourceRoot, $sourcePath); - } - - public function load(FilterInterface $additionalFilter = null) - { - $this->doLoad($this->string, $additionalFilter); - } - - public function setLastModified($lastModified) - { - $this->lastModified = $lastModified; - } - - public function getLastModified() - { - return $this->lastModified; - } -} diff --git a/src/Assetic/AssetManager.php b/src/Assetic/AssetManager.php deleted file mode 100644 index 1dfb66d6e..000000000 --- a/src/Assetic/AssetManager.php +++ /dev/null @@ -1,87 +0,0 @@ - - */ -class AssetManager -{ - private $assets = array(); - - /** - * Gets an asset by name. - * - * @param string $name The asset name - * - * @return AssetInterface The asset - * - * @throws \InvalidArgumentException If there is no asset by that name - */ - public function get($name) - { - if (!isset($this->assets[$name])) { - throw new \InvalidArgumentException(sprintf('There is no "%s" asset.', $name)); - } - - return $this->assets[$name]; - } - - /** - * Checks if the current asset manager has a certain asset. - * - * @param string $name an asset name - * - * @return Boolean True if the asset has been set, false if not - */ - public function has($name) - { - return isset($this->assets[$name]); - } - - /** - * Registers an asset to the current asset manager. - * - * @param string $name The asset name - * @param AssetInterface $asset The asset - * - * @throws \InvalidArgumentException If the asset name is invalid - */ - public function set($name, AssetInterface $asset) - { - if (!ctype_alnum(str_replace('_', '', $name))) { - throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $name)); - } - - $this->assets[$name] = $asset; - } - - /** - * Returns an array of asset names. - * - * @return array An array of asset names - */ - public function getNames() - { - return array_keys($this->assets); - } - - /** - * Clears all assets. - */ - public function clear() - { - $this->assets = array(); - } -} diff --git a/src/Assetic/AssetWriter.php b/src/Assetic/AssetWriter.php deleted file mode 100644 index 89cb69896..000000000 --- a/src/Assetic/AssetWriter.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @author Johannes M. Schmitt - */ -class AssetWriter -{ - private $dir; - private $values; - - /** - * Constructor. - * - * @param string $dir The base web directory - * @param array $values Variable values - * - * @throws \InvalidArgumentException if a variable value is not a string - */ - public function __construct($dir, array $values = array()) - { - foreach ($values as $var => $vals) { - foreach ($vals as $value) { - if (!is_string($value)) { - throw new \InvalidArgumentException(sprintf('All variable values must be strings, but got %s for variable "%s".', json_encode($value), $var)); - } - } - } - - $this->dir = $dir; - $this->values = $values; - } - - public function writeManagerAssets(AssetManager $am) - { - foreach ($am->getNames() as $name) { - $this->writeAsset($am->get($name)); - } - } - - public function writeAsset(AssetInterface $asset) - { - foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) { - $asset->setValues($combination); - - static::write( - $this->dir.'/'.VarUtils::resolve( - $asset->getTargetPath(), - $asset->getVars(), - $asset->getValues() - ), - $asset->dump() - ); - } - } - - protected static function write($path, $contents) - { - 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, $contents)) { - throw new \RuntimeException('Unable to write file '.$path); - } - } - - /** - * Not used. - * - * This method is provided for backward compatibility with certain versions - * of AsseticBundle. - */ - private function getCombinations(array $vars) - { - return VarUtils::getCombinations($vars, $this->values); - } -} diff --git a/src/Assetic/Cache/ApcCache.php b/src/Assetic/Cache/ApcCache.php deleted file mode 100644 index 71646b92e..000000000 --- a/src/Assetic/Cache/ApcCache.php +++ /dev/null @@ -1,64 +0,0 @@ - - */ -class ApcCache implements CacheInterface -{ - public $ttl = 0; - - /** - * @see CacheInterface::has() - */ - public function has($key) - { - return apc_exists($key); - } - - /** - * @see CacheInterface::get() - */ - public function get($key) - { - $value = apc_fetch($key, $success); - - if (!$success) { - throw new \RuntimeException('There is no cached value for '.$key); - } - - return $value; - } - - /** - * @see CacheInterface::set() - */ - public function set($key, $value) - { - $store = apc_store($key, $value, $this->ttl); - - if (!$store) { - throw new \RuntimeException('Unable to store "'.$key.'" for '.$this->ttl.' seconds.'); - } - - return $store; - } - - /** - * @see CacheInterface::remove() - */ - public function remove($key) - { - return apc_delete($key); - } -} diff --git a/src/Assetic/Cache/ArrayCache.php b/src/Assetic/Cache/ArrayCache.php deleted file mode 100644 index 8aaccd14b..000000000 --- a/src/Assetic/Cache/ArrayCache.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ -class ArrayCache implements CacheInterface -{ - private $cache = array(); - - /** - * @see CacheInterface::has() - */ - public function has($key) - { - return isset($this->cache[$key]); - } - - /** - * @see CacheInterface::get() - */ - public function get($key) - { - if (!$this->has($key)) { - throw new \RuntimeException('There is no cached value for '.$key); - } - - return $this->cache[$key]; - } - - /** - * @see CacheInterface::set() - */ - public function set($key, $value) - { - $this->cache[$key] = $value; - } - - /** - * @see CacheInterface::remove() - */ - public function remove($key) - { - unset($this->cache[$key]); - } -} diff --git a/src/Assetic/Cache/CacheInterface.php b/src/Assetic/Cache/CacheInterface.php deleted file mode 100644 index 6cc2008e4..000000000 --- a/src/Assetic/Cache/CacheInterface.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -interface CacheInterface -{ - /** - * Checks if the cache has a value for a key. - * - * @param string $key A unique key - * - * @return Boolean Whether the cache has a value for this key - */ - public function has($key); - - /** - * Returns the value for a key. - * - * @param string $key A unique key - * - * @return string|null The value in the cache - */ - public function get($key); - - /** - * Sets a value in the cache. - * - * @param string $key A unique key - * @param string $value The value to cache - */ - public function set($key, $value); - - /** - * Removes a value from the cache. - * - * @param string $key A unique key - */ - public function remove($key); -} diff --git a/src/Assetic/Cache/ConfigCache.php b/src/Assetic/Cache/ConfigCache.php deleted file mode 100644 index 1123f90a9..000000000 --- a/src/Assetic/Cache/ConfigCache.php +++ /dev/null @@ -1,121 +0,0 @@ - - */ -class ConfigCache -{ - private $dir; - - /** - * Construct. - * - * @param string $dir The cache directory - */ - public function __construct($dir) - { - $this->dir = $dir; - } - - /** - * Checks of the cache has a file. - * - * @param string $resource A cache key - * - * @return Boolean True if a file exists - */ - public function has($resource) - { - return file_exists($this->getSourcePath($resource)); - } - - /** - * Writes a value to a file. - * - * @param string $resource A cache key - * @param mixed $value A value to cache - */ - public function set($resource, $value) - { - $path = $this->getSourcePath($resource); - - if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) { - // @codeCoverageIgnoreStart - throw new \RuntimeException('Unable to create directory '.$dir); - // @codeCoverageIgnoreEnd - } - - if (false === @file_put_contents($path, sprintf("getSourcePath($resource); - - if (!file_exists($path)) { - throw new \RuntimeException('There is no cached value for '.$resource); - } - - return include $path; - } - - /** - * Returns a timestamp for when the cache was created. - * - * @param string $resource A cache key - * - * @return integer A UNIX timestamp - */ - public function getTimestamp($resource) - { - $path = $this->getSourcePath($resource); - - if (!file_exists($path)) { - throw new \RuntimeException('There is no cached value for '.$resource); - } - - if (false === $mtime = @filemtime($path)) { - // @codeCoverageIgnoreStart - throw new \RuntimeException('Unable to determine file mtime for '.$path); - // @codeCoverageIgnoreEnd - } - - return $mtime; - } - - /** - * Returns the path where the file corresponding to the supplied cache key can be included from. - * - * @param string $resource A cache key - * - * @return string A file path - */ - private function getSourcePath($resource) - { - $key = md5($resource); - - return $this->dir.'/'.$key[0].'/'.$key.'.php'; - } -} diff --git a/src/Assetic/Cache/ExpiringCache.php b/src/Assetic/Cache/ExpiringCache.php deleted file mode 100644 index 6f972d806..000000000 --- a/src/Assetic/Cache/ExpiringCache.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -class ExpiringCache implements CacheInterface -{ - private $cache; - private $lifetime; - - public function __construct(CacheInterface $cache, $lifetime) - { - $this->cache = $cache; - $this->lifetime = $lifetime; - } - - public function has($key) - { - if ($this->cache->has($key)) { - if (time() < $this->cache->get($key.'.expires')) { - return true; - } - - $this->cache->remove($key.'.expires'); - $this->cache->remove($key); - } - - return false; - } - - public function get($key) - { - return $this->cache->get($key); - } - - public function set($key, $value) - { - $this->cache->set($key.'.expires', time() + $this->lifetime); - $this->cache->set($key, $value); - } - - public function remove($key) - { - $this->cache->remove($key.'.expires'); - $this->cache->remove($key); - } -} diff --git a/src/Assetic/Cache/FilesystemCache.php b/src/Assetic/Cache/FilesystemCache.php deleted file mode 100644 index aa5981757..000000000 --- a/src/Assetic/Cache/FilesystemCache.php +++ /dev/null @@ -1,61 +0,0 @@ -dir = $dir; - } - - public function has($key) - { - return file_exists($this->dir.'/'.$key); - } - - public function get($key) - { - $path = $this->dir.'/'.$key; - - if (!file_exists($path)) { - throw new RuntimeException('There is no cached value for '.$key); - } - - return file_get_contents($path); - } - - public function set($key, $value) - { - if (!is_dir($this->dir) && false === @mkdir($this->dir, 0777, true)) { - throw new RuntimeException('Unable to create directory '.$this->dir); - } - - $path = $this->dir.'/'.$key; - - if (false === @file_put_contents($path, $value)) { - throw new RuntimeException('Unable to write file '.$path); - } - - File::chmod($path); - } - - public function remove($key) - { - $path = $this->dir.'/'.$key; - - if (file_exists($path) && false === @unlink($path)) { - throw new RuntimeException('Unable to remove file '.$path); - } - } -} diff --git a/src/Assetic/Exception/Exception.php b/src/Assetic/Exception/Exception.php deleted file mode 100644 index b03c19976..000000000 --- a/src/Assetic/Exception/Exception.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -interface Exception -{ -} diff --git a/src/Assetic/Exception/FilterException.php b/src/Assetic/Exception/FilterException.php deleted file mode 100644 index 4606cd128..000000000 --- a/src/Assetic/Exception/FilterException.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -class FilterException extends \RuntimeException implements Exception -{ - private $originalMessage; - private $input; - - public function __construct($message, $code = 0, \Exception $previous = null) - { - parent::__construct($message, $code, $previous); - - $this->originalMessage = $message; - } - - public function setInput($input) - { - $this->input = $input; - $this->updateMessage(); - - return $this; - } - - public function getInput() - { - return $this->input; - } - - private function updateMessage() - { - $message = $this->originalMessage; - - if (!empty($this->input)) { - $message .= "\n\nInput:\n".$this->input; - } - - $this->message = $message; - } -} diff --git a/src/Assetic/Factory/AssetFactory.php b/src/Assetic/Factory/AssetFactory.php deleted file mode 100644 index add30143a..000000000 --- a/src/Assetic/Factory/AssetFactory.php +++ /dev/null @@ -1,422 +0,0 @@ - - */ -class AssetFactory -{ - private $root; - private $debug; - private $output; - private $workers; - private $am; - private $fm; - - /** - * Constructor. - * - * @param string $root The default root directory - * @param Boolean $debug Filters prefixed with a "?" will be omitted in debug mode - */ - public function __construct($root, $debug = false) - { - $this->root = rtrim($root, '/'); - $this->debug = $debug; - $this->output = 'assetic/*'; - $this->workers = array(); - } - - /** - * Sets debug mode for the current factory. - * - * @param Boolean $debug Debug mode - */ - public function setDebug($debug) - { - $this->debug = $debug; - } - - /** - * Checks if the factory is in debug mode. - * - * @return Boolean Debug mode - */ - public function isDebug() - { - return $this->debug; - } - - /** - * Sets the default output string. - * - * @param string $output The default output string - */ - public function setDefaultOutput($output) - { - $this->output = $output; - } - - /** - * Adds a factory worker. - * - * @param WorkerInterface $worker A worker - */ - public function addWorker(WorkerInterface $worker) - { - $this->workers[] = $worker; - } - - /** - * Returns the current asset manager. - * - * @return AssetManager|null The asset manager - */ - public function getAssetManager() - { - return $this->am; - } - - /** - * Sets the asset manager to use when creating asset references. - * - * @param AssetManager $am The asset manager - */ - public function setAssetManager(AssetManager $am) - { - $this->am = $am; - } - - /** - * Returns the current filter manager. - * - * @return FilterManager|null The filter manager - */ - public function getFilterManager() - { - return $this->fm; - } - - /** - * Sets the filter manager to use when adding filters. - * - * @param FilterManager $fm The filter manager - */ - public function setFilterManager(FilterManager $fm) - { - $this->fm = $fm; - } - - /** - * Creates a new asset. - * - * Prefixing a filter name with a question mark will cause it to be - * omitted when the factory is in debug mode. - * - * Available options: - * - * * output: An output string - * * name: An asset name for interpolation in output patterns - * * debug: Forces debug mode on or off for this asset - * * root: An array or string of more root directories - * - * @param array|string $inputs An array of input strings - * @param array|string $filters An array of filter names - * @param array $options An array of options - * - * @return AssetCollection An asset collection - */ - public function createAsset($inputs = array(), $filters = array(), array $options = array()) - { - if (!is_array($inputs)) { - $inputs = array($inputs); - } - - if (!is_array($filters)) { - $filters = array($filters); - } - - if (!isset($options['output'])) { - $options['output'] = $this->output; - } - - if (!isset($options['vars'])) { - $options['vars'] = array(); - } - - if (!isset($options['debug'])) { - $options['debug'] = $this->debug; - } - - if (!isset($options['root'])) { - $options['root'] = array($this->root); - } else { - if (!is_array($options['root'])) { - $options['root'] = array($options['root']); - } - - $options['root'][] = $this->root; - } - - if (!isset($options['name'])) { - $options['name'] = $this->generateAssetName($inputs, $filters, $options); - } - - $asset = $this->createAssetCollection(array(), $options); - $extensions = array(); - - // inner assets - foreach ($inputs as $input) { - if (is_array($input)) { - // nested formula - $asset->add(call_user_func_array(array($this, 'createAsset'), $input)); - } else { - $asset->add($this->parseInput($input, $options)); - $extensions[pathinfo($input, PATHINFO_EXTENSION)] = true; - } - } - - // filters - foreach ($filters as $filter) { - if ('?' != $filter[0]) { - $asset->ensureFilter($this->getFilter($filter)); - } elseif (!$options['debug']) { - $asset->ensureFilter($this->getFilter(substr($filter, 1))); - } - } - - // append variables - if (!empty($options['vars'])) { - $toAdd = array(); - foreach ($options['vars'] as $var) { - if (false !== strpos($options['output'], '{'.$var.'}')) { - continue; - } - - $toAdd[] = '{'.$var.'}'; - } - - if ($toAdd) { - $options['output'] = str_replace('*', '*.'.implode('.', $toAdd), $options['output']); - } - } - - // append consensus extension if missing - if (1 == count($extensions) && !pathinfo($options['output'], PATHINFO_EXTENSION) && $extension = key($extensions)) { - $options['output'] .= '.'.$extension; - } - - // output --> target url - $asset->setTargetPath(str_replace('*', $options['name'], $options['output'])); - - // apply workers and return - return $this->applyWorkers($asset); - } - - public function generateAssetName($inputs, $filters, $options = array()) - { - foreach (array_diff(array_keys($options), array('output', 'debug', 'root')) as $key) { - unset($options[$key]); - } - - ksort($options); - - return substr(sha1(serialize($inputs).serialize($filters).serialize($options)), 0, 7); - } - - public function getLastModified(AssetInterface $asset) - { - $mtime = 0; - foreach ($asset instanceof AssetCollectionInterface ? $asset : array($asset) as $leaf) { - $mtime = max($mtime, $leaf->getLastModified()); - - if (!$filters = $leaf->getFilters()) { - continue; - } - - $prevFilters = array(); - foreach ($filters as $filter) { - $prevFilters[] = $filter; - - if (!$filter instanceof DependencyExtractorInterface) { - continue; - } - - // extract children from leaf after running all preceeding filters - $clone = clone $leaf; - $clone->clearFilters(); - foreach (array_slice($prevFilters, 0, -1) as $prevFilter) { - $clone->ensureFilter($prevFilter); - } - $clone->load(); - - foreach ($filter->getChildren($this, $clone->getContent(), $clone->getSourceDirectory()) as $child) { - $mtime = max($mtime, $this->getLastModified($child)); - } - } - } - - return $mtime; - } - - /** - * Parses an input string string into an asset. - * - * The input string can be one of the following: - * - * * A reference: If the string starts with an "at" sign it will be interpreted as a reference to an asset in the asset manager - * * An absolute URL: If the string contains "://" or starts with "//" it will be interpreted as an HTTP asset - * * A glob: If the string contains a "*" it will be interpreted as a glob - * * A path: Otherwise the string is interpreted as a filesystem path - * - * Both globs and paths will be absolutized using the current root directory. - * - * @param string $input An input string - * @param array $options An array of options - * - * @return AssetInterface An asset - */ - protected function parseInput($input, array $options = array()) - { - if ('@' == $input[0]) { - return $this->createAssetReference(substr($input, 1)); - } - - if (false !== strpos($input, '://') || 0 === strpos($input, '//')) { - return $this->createHttpAsset($input, $options['vars']); - } - - if (self::isAbsolutePath($input)) { - if ($root = self::findRootDir($input, $options['root'])) { - $path = ltrim(substr($input, strlen($root)), '/'); - } else { - $path = null; - } - } else { - $root = $this->root; - $path = $input; - $input = $this->root.'/'.$path; - } - - if (false !== strpos($input, '*')) { - return $this->createGlobAsset($input, $root, $options['vars']); - } - - return $this->createFileAsset($input, $root, $path, $options['vars']); - } - - protected function createAssetCollection(array $assets = array(), array $options = array()) - { - return new AssetCollection($assets, array(), null, isset($options['vars']) ? $options['vars'] : array()); - } - - protected function createAssetReference($name) - { - if (!$this->am) { - throw new \LogicException('There is no asset manager.'); - } - - return new AssetReference($this->am, $name); - } - - protected function createHttpAsset($sourceUrl, $vars) - { - return new HttpAsset($sourceUrl, array(), false, $vars); - } - - protected function createGlobAsset($glob, $root = null, $vars = []) - { - return new GlobAsset($glob, array(), $root, $vars); - } - - protected function createFileAsset($source, $root = null, $path = null, $vars = []) - { - return new FileAsset($source, array(), $root, $path, $vars); - } - - protected function getFilter($name) - { - if (!$this->fm) { - throw new \LogicException('There is no filter manager.'); - } - - return $this->fm->get($name); - } - - /** - * Filters an asset collection through the factory workers. - * - * Each leaf asset will be processed first, followed by the asset - * collection itself. - * - * @param AssetCollectionInterface $asset An asset collection - * - * @return AssetCollectionInterface - */ - private function applyWorkers(AssetCollectionInterface $asset) - { - foreach ($asset as $leaf) { - foreach ($this->workers as $worker) { - $retval = $worker->process($leaf, $this); - - if ($retval instanceof AssetInterface && $leaf !== $retval) { - $asset->replaceLeaf($leaf, $retval); - } - } - } - - foreach ($this->workers as $worker) { - $retval = $worker->process($asset, $this); - - if ($retval instanceof AssetInterface) { - $asset = $retval; - } - } - - return $asset instanceof AssetCollectionInterface ? $asset : $this->createAssetCollection(array($asset)); - } - - private static function isAbsolutePath($path) - { - return '/' == $path[0] || '\\' == $path[0] || (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] == ':' && ('\\' == $path[2] || '/' == $path[2])); - } - - /** - * Loops through the root directories and returns the first match. - * - * @param string $path An absolute path - * @param array $roots An array of root directories - * - * @return string|null The matching root directory, if found - */ - private static function findRootDir($path, array $roots) - { - foreach ($roots as $root) { - if (0 === strpos($path, $root)) { - return $root; - } - } - } -} diff --git a/src/Assetic/Factory/LazyAssetManager.php b/src/Assetic/Factory/LazyAssetManager.php deleted file mode 100644 index 65f08c10d..000000000 --- a/src/Assetic/Factory/LazyAssetManager.php +++ /dev/null @@ -1,208 +0,0 @@ - - */ -class LazyAssetManager extends AssetManager -{ - private $factory; - private $loaders; - private $resources; - private $formulae; - private $loaded; - private $loading; - - /** - * Constructor. - * - * @param AssetFactory $factory The asset factory - * @param array $loaders An array of loaders indexed by alias - */ - public function __construct(AssetFactory $factory, $loaders = array()) - { - $this->factory = $factory; - $this->loaders = array(); - $this->resources = array(); - $this->formulae = array(); - $this->loaded = false; - $this->loading = false; - - foreach ($loaders as $alias => $loader) { - $this->setLoader($alias, $loader); - } - } - - /** - * Adds a loader to the asset manager. - * - * @param string $alias An alias for the loader - * @param FormulaLoaderInterface $loader A loader - */ - public function setLoader($alias, FormulaLoaderInterface $loader) - { - $this->loaders[$alias] = $loader; - $this->loaded = false; - } - - /** - * Adds a resource to the asset manager. - * - * @param ResourceInterface $resource A resource - * @param string $loader The loader alias for this resource - */ - public function addResource(ResourceInterface $resource, $loader) - { - $this->resources[$loader][] = $resource; - $this->loaded = false; - } - - /** - * Returns an array of resources. - * - * @return array An array of resources - */ - public function getResources() - { - $resources = array(); - foreach ($this->resources as $r) { - $resources = array_merge($resources, $r); - } - - return $resources; - } - - /** - * Checks for an asset formula. - * - * @param string $name An asset name - * - * @return Boolean If there is a formula - */ - public function hasFormula($name) - { - if (!$this->loaded) { - $this->load(); - } - - return isset($this->formulae[$name]); - } - - /** - * Returns an asset's formula. - * - * @param string $name An asset name - * - * @return array The formula - * - * @throws \InvalidArgumentException If there is no formula by that name - */ - public function getFormula($name) - { - if (!$this->loaded) { - $this->load(); - } - - if (!isset($this->formulae[$name])) { - throw new \InvalidArgumentException(sprintf('There is no "%s" formula.', $name)); - } - - return $this->formulae[$name]; - } - - /** - * Sets a formula on the asset manager. - * - * @param string $name An asset name - * @param array $formula A formula - */ - public function setFormula($name, array $formula) - { - $this->formulae[$name] = $formula; - } - - /** - * Loads formulae from resources. - * - * @throws \LogicException If a resource has been added to an invalid loader - */ - public function load() - { - if ($this->loading) { - return; - } - - if ($diff = array_diff(array_keys($this->resources), array_keys($this->loaders))) { - throw new \LogicException('The following loader(s) are not registered: '.implode(', ', $diff)); - } - - $this->loading = true; - - foreach ($this->resources as $loader => $resources) { - foreach ($resources as $resource) { - $this->formulae = array_replace($this->formulae, $this->loaders[$loader]->load($resource)); - } - } - - $this->loaded = true; - $this->loading = false; - } - - public function get($name) - { - if (!$this->loaded) { - $this->load(); - } - - if (!parent::has($name) && isset($this->formulae[$name])) { - list($inputs, $filters, $options) = $this->formulae[$name]; - $options['name'] = $name; - parent::set($name, $this->factory->createAsset($inputs, $filters, $options)); - } - - return parent::get($name); - } - - public function has($name) - { - if (!$this->loaded) { - $this->load(); - } - - return isset($this->formulae[$name]) || parent::has($name); - } - - public function getNames() - { - if (!$this->loaded) { - $this->load(); - } - - return array_unique(array_merge(parent::getNames(), array_keys($this->formulae))); - } - - public function isDebug() - { - return $this->factory->isDebug(); - } - - public function getLastModified(AssetInterface $asset) - { - return $this->factory->getLastModified($asset); - } -} diff --git a/src/Assetic/Factory/Loader/BasePhpFormulaLoader.php b/src/Assetic/Factory/Loader/BasePhpFormulaLoader.php deleted file mode 100644 index 78522debc..000000000 --- a/src/Assetic/Factory/Loader/BasePhpFormulaLoader.php +++ /dev/null @@ -1,162 +0,0 @@ - - */ -abstract class BasePhpFormulaLoader implements FormulaLoaderInterface -{ - protected $factory; - protected $prototypes; - - public function __construct(AssetFactory $factory) - { - $this->factory = $factory; - $this->prototypes = array(); - - foreach ($this->registerPrototypes() as $prototype => $options) { - $this->addPrototype($prototype, $options); - } - } - - public function addPrototype($prototype, array $options = array()) - { - $tokens = token_get_all('prototypes[$prototype] = array($tokens, $options); - } - - public function load(ResourceInterface $resource) - { - if (!$nbProtos = count($this->prototypes)) { - throw new \LogicException('There are no prototypes registered.'); - } - - $buffers = array_fill(0, $nbProtos, ''); - $bufferLevels = array_fill(0, $nbProtos, 0); - $buffersInWildcard = array(); - - $tokens = token_get_all($resource->getContent()); - $calls = array(); - - while ($token = array_shift($tokens)) { - $current = self::tokenToString($token); - // loop through each prototype (by reference) - foreach (array_keys($this->prototypes) as $i) { - $prototype = & $this->prototypes[$i][0]; - $options = $this->prototypes[$i][1]; - $buffer = & $buffers[$i]; - $level = & $bufferLevels[$i]; - - if (isset($buffersInWildcard[$i])) { - switch ($current) { - case '(': - ++$level; - break; - case ')': - --$level; - break; - } - - $buffer .= $current; - - if (!$level) { - $calls[] = array($buffer.';', $options); - $buffer = ''; - unset($buffersInWildcard[$i]); - } - } elseif ($current == self::tokenToString(current($prototype))) { - $buffer .= $current; - if ('*' == self::tokenToString(next($prototype))) { - $buffersInWildcard[$i] = true; - ++$level; - } - } else { - reset($prototype); - unset($buffersInWildcard[$i]); - $buffer = ''; - } - } - } - - $formulae = array(); - foreach ($calls as $call) { - $formulae += call_user_func_array(array($this, 'processCall'), $call); - } - - return $formulae; - } - - private function processCall($call, array $protoOptions = array()) - { - $tmp = FilesystemUtils::createTemporaryFile('php_formula_loader'); - file_put_contents($tmp, implode("\n", array( - 'registerSetupCode(), - $call, - 'echo serialize($_call);', - ))); - $args = unserialize(shell_exec('php '.escapeshellarg($tmp))); - unlink($tmp); - - $inputs = isset($args[0]) ? self::argumentToArray($args[0]) : array(); - $filters = isset($args[1]) ? self::argumentToArray($args[1]) : array(); - $options = isset($args[2]) ? $args[2] : array(); - - if (!isset($options['debug'])) { - $options['debug'] = $this->factory->isDebug(); - } - - if (!is_array($options)) { - throw new \RuntimeException('The third argument must be omitted, null or an array.'); - } - - // apply the prototype options - $options += $protoOptions; - - if (!isset($options['name'])) { - $options['name'] = $this->factory->generateAssetName($inputs, $filters, $options); - } - - return array($options['name'] => array($inputs, $filters, $options)); - } - - /** - * Returns an array of prototypical calls and options. - * - * @return array Prototypes and options - */ - abstract protected function registerPrototypes(); - - /** - * Returns setup code for the reflection scriptlet. - * - * @return string Some PHP setup code - */ - abstract protected function registerSetupCode(); - - protected static function tokenToString($token) - { - return is_array($token) ? $token[1] : $token; - } - - protected static function argumentToArray($argument) - { - return is_array($argument) ? $argument : array_filter(array_map('trim', explode(',', $argument))); - } -} diff --git a/src/Assetic/Factory/Loader/CachedFormulaLoader.php b/src/Assetic/Factory/Loader/CachedFormulaLoader.php deleted file mode 100644 index 7ac943979..000000000 --- a/src/Assetic/Factory/Loader/CachedFormulaLoader.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ -class CachedFormulaLoader implements FormulaLoaderInterface -{ - private $loader; - private $configCache; - private $debug; - - /** - * Constructor. - * - * When the loader is in debug mode it will ensure the cached formulae - * are fresh before returning them. - * - * @param FormulaLoaderInterface $loader A formula loader - * @param ConfigCache $configCache A config cache - * @param Boolean $debug The debug mode - */ - public function __construct(FormulaLoaderInterface $loader, ConfigCache $configCache, $debug = false) - { - $this->loader = $loader; - $this->configCache = $configCache; - $this->debug = $debug; - } - - public function load(ResourceInterface $resources) - { - if (!$resources instanceof IteratorResourceInterface) { - $resources = array($resources); - } - - $formulae = array(); - - foreach ($resources as $resource) { - $id = (string) $resource; - if (!$this->configCache->has($id) || ($this->debug && !$resource->isFresh($this->configCache->getTimestamp($id)))) { - $formulae += $this->loader->load($resource); - $this->configCache->set($id, $formulae); - } else { - $formulae += $this->configCache->get($id); - } - } - - return $formulae; - } -} diff --git a/src/Assetic/Factory/Loader/FormulaLoaderInterface.php b/src/Assetic/Factory/Loader/FormulaLoaderInterface.php deleted file mode 100644 index e902ad2e1..000000000 --- a/src/Assetic/Factory/Loader/FormulaLoaderInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -interface FormulaLoaderInterface -{ - /** - * Loads formulae from a resource. - * - * Formulae should be loaded the same regardless of the current debug - * mode. Debug considerations should happen downstream. - * - * @param ResourceInterface $resource A resource - * - * @return array An array of formulae - */ - public function load(ResourceInterface $resource); -} diff --git a/src/Assetic/Factory/Loader/FunctionCallsFormulaLoader.php b/src/Assetic/Factory/Loader/FunctionCallsFormulaLoader.php deleted file mode 100644 index ceb46707b..000000000 --- a/src/Assetic/Factory/Loader/FunctionCallsFormulaLoader.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class FunctionCallsFormulaLoader extends BasePhpFormulaLoader -{ - protected function registerPrototypes() - { - return array( - 'assetic_javascripts(*)' => array('output' => 'js/*.js'), - 'assetic_stylesheets(*)' => array('output' => 'css/*.css'), - 'assetic_image(*)' => array('output' => 'images/*'), - ); - } - - protected function registerSetupCode() - { - return <<<'EOF' -function assetic_javascripts() -{ - global $_call; - $_call = func_get_args(); -} - -function assetic_stylesheets() -{ - global $_call; - $_call = func_get_args(); -} - -function assetic_image() -{ - global $_call; - $_call = func_get_args(); -} - -EOF; - } -} diff --git a/src/Assetic/Factory/Resource/CoalescingDirectoryResource.php b/src/Assetic/Factory/Resource/CoalescingDirectoryResource.php deleted file mode 100644 index 1f184be5c..000000000 --- a/src/Assetic/Factory/Resource/CoalescingDirectoryResource.php +++ /dev/null @@ -1,112 +0,0 @@ - - */ -class CoalescingDirectoryResource implements IteratorResourceInterface -{ - private $directories; - - public function __construct($directories) - { - $this->directories = array(); - - foreach ($directories as $directory) { - $this->addDirectory($directory); - } - } - - public function addDirectory(IteratorResourceInterface $directory) - { - $this->directories[] = $directory; - } - - public function isFresh($timestamp) - { - foreach ($this->getFileResources() as $file) { - if (!$file->isFresh($timestamp)) { - return false; - } - } - - return true; - } - - public function getContent() - { - $parts = array(); - foreach ($this->getFileResources() as $file) { - $parts[] = $file->getContent(); - } - - return implode("\n", $parts); - } - - /** - * Returns a string to uniquely identify the current resource. - * - * @return string An identifying string - */ - public function __toString() - { - $parts = array(); - foreach ($this->directories as $directory) { - $parts[] = (string) $directory; - } - - return implode(',', $parts); - } - - public function getIterator(): Traversable - { - return new \ArrayIterator($this->getFileResources()); - } - - /** - * Returns the relative version of a filename. - * - * @param ResourceInterface $file The file - * @param ResourceInterface $directory The directory - * - * @return string The name to compare with files from other directories - */ - protected function getRelativeName(ResourceInterface $file, ResourceInterface $directory) - { - return substr((string) $file, strlen((string) $directory)); - } - - /** - * Performs the coalesce. - * - * @return array An array of file resources - */ - private function getFileResources() - { - $paths = array(); - - foreach ($this->directories as $directory) { - foreach ($directory as $file) { - $relative = $this->getRelativeName($file, $directory); - - if (!isset($paths[$relative])) { - $paths[$relative] = $file; - } - } - } - - return array_values($paths); - } -} diff --git a/src/Assetic/Factory/Resource/DirectoryResource.php b/src/Assetic/Factory/Resource/DirectoryResource.php deleted file mode 100644 index 27182621b..000000000 --- a/src/Assetic/Factory/Resource/DirectoryResource.php +++ /dev/null @@ -1,84 +0,0 @@ - - */ -class DirectoryResource implements IteratorResourceInterface -{ - private $path; - private $pattern; - - /** - * Constructor. - * - * @param string $path A directory path - * @param string $pattern A filename pattern - */ - public function __construct($path, $pattern = null) - { - if (DIRECTORY_SEPARATOR != substr($path, -1)) { - $path .= DIRECTORY_SEPARATOR; - } - - $this->path = $path; - $this->pattern = $pattern; - } - - public function isFresh($timestamp) - { - if (!is_dir($this->path) || filemtime($this->path) > $timestamp) { - return false; - } - - foreach ($this as $resource) { - if (!$resource->isFresh($timestamp)) { - return false; - } - } - - return true; - } - - /** - * Returns the combined content of all inner resources. - */ - public function getContent() - { - $content = array(); - foreach ($this as $resource) { - $content[] = $resource->getContent(); - } - - return implode("\n", $content); - } - - public function __toString() - { - return $this->path; - } - - public function getIterator(): Traversable - { - return is_dir($this->path) - ? new DirectoryResourceIterator($this->getInnerIterator()) - : new \EmptyIterator(); - } - - protected function getInnerIterator() - { - return new DirectoryResourceFilterIterator(new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS), $this->pattern); - } -} diff --git a/src/Assetic/Factory/Resource/DirectoryResourceFilterIterator.php b/src/Assetic/Factory/Resource/DirectoryResourceFilterIterator.php deleted file mode 100644 index 22fcb4dfc..000000000 --- a/src/Assetic/Factory/Resource/DirectoryResourceFilterIterator.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @access private - */ -class DirectoryResourceFilterIterator extends \RecursiveFilterIterator -{ - protected $pattern; - - public function __construct(\RecursiveDirectoryIterator $iterator, $pattern = null) - { - parent::__construct($iterator); - - $this->pattern = $pattern; - } - - public function accept() - { - $file = $this->current(); - $name = $file->getBasename(); - - if ($file->isDir()) { - return '.' != $name[0]; - } - - return null === $this->pattern || 0 < preg_match($this->pattern, $name); - } - - public function getChildren() - { - return new self(new \RecursiveDirectoryIterator($this->current()->getPathname(), \RecursiveDirectoryIterator::FOLLOW_SYMLINKS), $this->pattern); - } -} diff --git a/src/Assetic/Factory/Resource/DirectoryResourceIterator.php b/src/Assetic/Factory/Resource/DirectoryResourceIterator.php deleted file mode 100644 index 3e8f75c87..000000000 --- a/src/Assetic/Factory/Resource/DirectoryResourceIterator.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @access private - */ -class DirectoryResourceIterator extends \RecursiveIteratorIterator -{ - public function current() - { - return new FileResource(parent::current()->getPathname()); - } -} diff --git a/src/Assetic/Factory/Resource/FileResource.php b/src/Assetic/Factory/Resource/FileResource.php deleted file mode 100644 index de49c259e..000000000 --- a/src/Assetic/Factory/Resource/FileResource.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -class FileResource implements ResourceInterface -{ - private $path; - - /** - * Constructor. - * - * @param string $path The path to a file - */ - public function __construct($path) - { - $this->path = $path; - } - - public function isFresh($timestamp) - { - return file_exists($this->path) && filemtime($this->path) <= $timestamp; - } - - public function getContent() - { - return file_exists($this->path) ? file_get_contents($this->path) : ''; - } - - public function __toString() - { - return $this->path; - } -} diff --git a/src/Assetic/Factory/Resource/IteratorResourceInterface.php b/src/Assetic/Factory/Resource/IteratorResourceInterface.php deleted file mode 100644 index ef9397549..000000000 --- a/src/Assetic/Factory/Resource/IteratorResourceInterface.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -interface IteratorResourceInterface extends ResourceInterface, \IteratorAggregate -{ -} diff --git a/src/Assetic/Factory/Resource/ResourceInterface.php b/src/Assetic/Factory/Resource/ResourceInterface.php deleted file mode 100644 index 23ee786ce..000000000 --- a/src/Assetic/Factory/Resource/ResourceInterface.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -interface ResourceInterface -{ - /** - * Checks if a timestamp represents the latest resource. - * - * @param integer $timestamp A UNIX timestamp - * - * @return Boolean True if the timestamp is up to date - */ - public function isFresh($timestamp); - - /** - * Returns the content of the resource. - * - * @return string The content - */ - public function getContent(); - - /** - * Returns a unique string for the current resource. - * - * @return string A unique string to identity the current resource - */ - public function __toString(); -} diff --git a/src/Assetic/Factory/Worker/CacheBustingWorker.php b/src/Assetic/Factory/Worker/CacheBustingWorker.php deleted file mode 100644 index 57baf6a92..000000000 --- a/src/Assetic/Factory/Worker/CacheBustingWorker.php +++ /dev/null @@ -1,68 +0,0 @@ - - */ -class CacheBustingWorker implements WorkerInterface -{ - private $separator; - - public function __construct($separator = '-') - { - $this->separator = $separator; - } - - public function process(AssetInterface $asset, AssetFactory $factory) - { - if (!$path = $asset->getTargetPath()) { - // no path to work with - return; - } - - if (!$search = pathinfo($path, PATHINFO_EXTENSION)) { - // nothing to replace - return; - } - - $replace = $this->separator.$this->getHash($asset, $factory).'.'.$search; - if (preg_match('/'.preg_quote($replace, '/').'$/', $path)) { - // already replaced - return; - } - - $asset->setTargetPath( - preg_replace('/\.'.preg_quote($search, '/').'$/', $replace, $path) - ); - } - - protected function getHash(AssetInterface $asset, AssetFactory $factory) - { - $hash = hash_init('sha1'); - - hash_update($hash, $factory->getLastModified($asset)); - - if ($asset instanceof AssetCollectionInterface) { - foreach ($asset as $i => $leaf) { - $sourcePath = $leaf->getSourcePath(); - hash_update($hash, $sourcePath ?: $i); - } - } - - return substr(hash_final($hash), 0, 7); - } -} diff --git a/src/Assetic/Factory/Worker/EnsureFilterWorker.php b/src/Assetic/Factory/Worker/EnsureFilterWorker.php deleted file mode 100644 index efc94956a..000000000 --- a/src/Assetic/Factory/Worker/EnsureFilterWorker.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @todo A better asset-matcher mechanism - */ -class EnsureFilterWorker implements WorkerInterface -{ - const CHECK_SOURCE = 1; - const CHECK_TARGET = 2; - - private $pattern; - private $filter; - private $flags; - - /** - * Constructor. - * - * @param string $pattern A regex for checking the asset's target URL - * @param FilterInterface $filter A filter to apply if the regex matches - * @param integer $flags Flags for what to check - */ - public function __construct($pattern, FilterInterface $filter, $flags = null) - { - if (null === $flags) { - $flags = self::CHECK_SOURCE | self::CHECK_TARGET; - } - - $this->pattern = $pattern; - $this->filter = $filter; - $this->flags = $flags; - } - - public function process(AssetInterface $asset, AssetFactory $factory) - { - if ( - (self::CHECK_SOURCE === (self::CHECK_SOURCE & $this->flags) && preg_match($this->pattern, $asset->getSourcePath())) - || - (self::CHECK_TARGET === (self::CHECK_TARGET & $this->flags) && preg_match($this->pattern, $asset->getTargetPath())) - ) { - $asset->ensureFilter($this->filter); - } - } -} diff --git a/src/Assetic/Factory/Worker/WorkerInterface.php b/src/Assetic/Factory/Worker/WorkerInterface.php deleted file mode 100644 index 3216fd8c9..000000000 --- a/src/Assetic/Factory/Worker/WorkerInterface.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -interface WorkerInterface -{ - /** - * Processes an asset. - * - * @param AssetInterface $asset An asset - * @param AssetFactory $factory The factory - * - * @return AssetInterface|null May optionally return a replacement asset - */ - public function process(AssetInterface $asset, AssetFactory $factory); -} diff --git a/src/Assetic/Filter/BaseCssFilter.php b/src/Assetic/Filter/BaseCssFilter.php deleted file mode 100644 index 966efe1f0..000000000 --- a/src/Assetic/Filter/BaseCssFilter.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -abstract class BaseCssFilter implements FilterInterface -{ - /** - * @see CssUtils::filterReferences() - */ - protected function filterReferences($content, $callback, $limit = -1, &$count = 0) - { - return CssUtils::filterReferences($content, $callback, $limit, $count); - } - - /** - * @see CssUtils::filterUrls() - */ - protected function filterUrls($content, $callback, $limit = -1, &$count = 0) - { - return CssUtils::filterUrls($content, $callback, $limit, $count); - } - - /** - * @see CssUtils::filterImports() - */ - protected function filterImports($content, $callback, $limit = -1, &$count = 0, $includeUrl = true) - { - return CssUtils::filterImports($content, $callback, $limit, $count, $includeUrl); - } - - /** - * @see CssUtils::filterIEFilters() - */ - protected function filterIEFilters($content, $callback, $limit = -1, &$count = 0) - { - return CssUtils::filterIEFilters($content, $callback, $limit, $count); - } -} diff --git a/src/Assetic/Filter/CallablesFilter.php b/src/Assetic/Filter/CallablesFilter.php deleted file mode 100644 index 15f425183..000000000 --- a/src/Assetic/Filter/CallablesFilter.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class CallablesFilter implements FilterInterface, DependencyExtractorInterface -{ - private $loader; - private $dumper; - private $extractor; - - /** - * @param callable|null $loader - * @param callable|null $dumper - * @param callable|null $extractor - */ - public function __construct($loader = null, $dumper = null, $extractor = null) - { - $this->loader = $loader; - $this->dumper = $dumper; - $this->extractor = $extractor; - } - - public function filterLoad(AssetInterface $asset) - { - if (null !== $callable = $this->loader) { - $callable($asset); - } - } - - public function filterDump(AssetInterface $asset) - { - if (null !== $callable = $this->dumper) { - $callable($asset); - } - } - - public function getChildren(AssetFactory $factory, $content, $loadPath = null) - { - if (null !== $callable = $this->extractor) { - return $callable($factory, $content, $loadPath); - } - - return array(); - } -} diff --git a/src/Assetic/Filter/CssCacheBustingFilter.php b/src/Assetic/Filter/CssCacheBustingFilter.php deleted file mode 100644 index 694103155..000000000 --- a/src/Assetic/Filter/CssCacheBustingFilter.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -class CssCacheBustingFilter extends BaseCssFilter -{ - private $version; - private $format = '%s?%s'; - - public function setVersion($version) - { - $this->version = $version; - } - - public function setFormat($versionFormat) - { - $this->format = $versionFormat; - } - - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - if (!$this->version) { - return; - } - - $version = $this->version; - $format = $this->format; - - $asset->setContent($this->filterReferences( - $asset->getContent(), - function ($matches) use ($version, $format) { - if (0 === strpos($matches['url'], 'data:')) { - return $matches[0]; - } - - return str_replace( - $matches['url'], - sprintf($format, $matches['url'], $version), - $matches[0] - ); - } - )); - } -} diff --git a/src/Assetic/Filter/CssImportFilter.php b/src/Assetic/Filter/CssImportFilter.php deleted file mode 100644 index b12f3c2c8..000000000 --- a/src/Assetic/Filter/CssImportFilter.php +++ /dev/null @@ -1,106 +0,0 @@ - - */ -class CssImportFilter extends BaseCssFilter implements DependencyExtractorInterface -{ - private $importFilter; - - /** - * Constructor. - * - * @param FilterInterface $importFilter Filter for each imported asset - */ - public function __construct(FilterInterface $importFilter = null) - { - $this->importFilter = $importFilter ?: new CssRewriteFilter(); - } - - public function filterLoad(AssetInterface $asset) - { - $importFilter = $this->importFilter; - $sourceRoot = $asset->getSourceRoot(); - $sourcePath = $asset->getSourcePath(); - - $callback = function ($matches) use ($importFilter, $sourceRoot, $sourcePath) { - if (!$matches['url'] || null === $sourceRoot) { - return $matches[0]; - } - - $importRoot = $sourceRoot; - - if (false !== strpos($matches['url'], '://')) { - // absolute - list($importScheme, $tmp) = explode('://', $matches['url'], 2); - list($importHost, $importPath) = explode('/', $tmp, 2); - $importRoot = $importScheme.'://'.$importHost; - } elseif (0 === strpos($matches['url'], '//')) { - // protocol-relative - list($importHost, $importPath) = explode('/', substr($matches['url'], 2), 2); - $importRoot = '//'.$importHost; - } elseif ('/' == $matches['url'][0]) { - // root-relative - $importPath = substr($matches['url'], 1); - } elseif (null !== $sourcePath) { - // document-relative - $importPath = $matches['url']; - if ('.' != $sourceDir = dirname($sourcePath)) { - $importPath = $sourceDir.'/'.$importPath; - } - } else { - return $matches[0]; - } - - $importSource = $importRoot.'/'.$importPath; - if (false !== strpos($importSource, '://') || 0 === strpos($importSource, '//')) { - $import = new HttpAsset($importSource, array($importFilter), true); - } elseif ('css' != pathinfo($importPath, PATHINFO_EXTENSION) || !file_exists($importSource)) { - // ignore non-css and non-existant imports - return $matches[0]; - } else { - $import = new FileAsset($importSource, array($importFilter), $importRoot, $importPath); - } - - $import->setTargetPath($sourcePath); - - return $import->dump(); - }; - - $content = $asset->getContent(); - $lastHash = md5($content); - - do { - $content = $this->filterImports($content, $callback); - $hash = md5($content); - } while ($lastHash != $hash && $lastHash = $hash); - - $asset->setContent($content); - } - - public function filterDump(AssetInterface $asset) - { - } - - public function getChildren(AssetFactory $factory, $content, $loadPath = null) - { - // todo - return array(); - } -} diff --git a/src/Assetic/Filter/CssMinFilter.php b/src/Assetic/Filter/CssMinFilter.php deleted file mode 100644 index 5538ad869..000000000 --- a/src/Assetic/Filter/CssMinFilter.php +++ /dev/null @@ -1,70 +0,0 @@ - - */ -class CssMinFilter implements FilterInterface -{ - private $filters; - private $plugins; - - public function __construct() - { - $this->filters = array(); - $this->plugins = array(); - } - - public function setFilters(array $filters) - { - $this->filters = $filters; - } - - public function setFilter($name, $value) - { - $this->filters[$name] = $value; - } - - public function setPlugins(array $plugins) - { - $this->plugins = $plugins; - } - - public function setPlugin($name, $value) - { - $this->plugins[$name] = $value; - } - - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $filters = $this->filters; - $plugins = $this->plugins; - - if (isset($filters['ImportImports']) && true === $filters['ImportImports']) { - if ($dir = $asset->getSourceDirectory()) { - $filters['ImportImports'] = array('BasePath' => $dir); - } else { - unset($filters['ImportImports']); - } - } - - $asset->setContent(\CssMin::minify($asset->getContent(), $filters, $plugins)); - } -} diff --git a/src/Assetic/Filter/CssRewriteFilter.php b/src/Assetic/Filter/CssRewriteFilter.php deleted file mode 100644 index cc21f369b..000000000 --- a/src/Assetic/Filter/CssRewriteFilter.php +++ /dev/null @@ -1,100 +0,0 @@ - - */ -class CssRewriteFilter extends BaseCssFilter -{ - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $sourceBase = $asset->getSourceRoot(); - $sourcePath = $asset->getSourcePath(); - $targetPath = $asset->getTargetPath(); - - if (null === $sourcePath || null === $targetPath || $sourcePath == $targetPath) { - return; - } - - // learn how to get from the target back to the source - if (false !== strpos($sourceBase, '://')) { - list($scheme, $url) = explode('://', $sourceBase.'/'.$sourcePath, 2); - list($host, $path) = explode('/', $url, 2); - - $host = $scheme.'://'.$host.'/'; - $path = false === strpos($path, '/') ? '' : dirname($path); - $path .= '/'; - } else { - // assume source and target are on the same host - $host = ''; - - // pop entries off the target until it fits in the source - if ('.' == dirname($sourcePath)) { - $path = str_repeat('../', substr_count($targetPath, '/')); - } elseif ('.' == $targetDir = dirname($targetPath)) { - $path = dirname($sourcePath).'/'; - } else { - $path = ''; - while (0 !== strpos($sourcePath, $targetDir)) { - if (false !== $pos = strrpos($targetDir, '/')) { - $targetDir = substr($targetDir, 0, $pos); - $path .= '../'; - } else { - $targetDir = ''; - $path .= '../'; - break; - } - } - $path .= ltrim(substr(dirname($sourcePath).'/', strlen($targetDir)), '/'); - } - } - - $content = $this->filterReferences($asset->getContent(), function ($matches) use ($host, $path) { - if (false !== strpos($matches['url'], '://') || 0 === strpos($matches['url'], '//') || 0 === strpos($matches['url'], 'data:')) { - // absolute or protocol-relative or data uri - return $matches[0]; - } - - if (isset($matches['url'][0]) && '/' == $matches['url'][0]) { - // root relative - return str_replace($matches['url'], $host.$matches['url'], $matches[0]); - } - - // document relative - $url = $matches['url']; - while (0 === strpos($url, '../') && 2 <= substr_count($path, '/')) { - $path = substr($path, 0, strrpos(rtrim($path, '/'), '/') + 1); - $url = substr($url, 3); - } - - $parts = array(); - foreach (explode('/', $host.$path.$url) as $part) { - if ('..' === $part && count($parts) && '..' !== end($parts)) { - array_pop($parts); - } else { - $parts[] = $part; - } - } - - return str_replace($matches['url'], implode('/', $parts), $matches[0]); - }); - - $asset->setContent($content); - } -} diff --git a/src/Assetic/Filter/DependencyExtractorInterface.php b/src/Assetic/Filter/DependencyExtractorInterface.php deleted file mode 100644 index 047b0006c..000000000 --- a/src/Assetic/Filter/DependencyExtractorInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -interface DependencyExtractorInterface extends FilterInterface -{ - /** - * Returns child assets. - * - * @param AssetFactory $factory The asset factory - * @param string $content The asset content - * @param string $loadPath An optional load path - * - * @return AssetInterface[] Child assets - */ - public function getChildren(AssetFactory $factory, $content, $loadPath = null); -} diff --git a/src/Assetic/Filter/FilterCollection.php b/src/Assetic/Filter/FilterCollection.php deleted file mode 100644 index 502ec84ce..000000000 --- a/src/Assetic/Filter/FilterCollection.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ -class FilterCollection implements FilterInterface, \IteratorAggregate, \Countable -{ - private $filters = array(); - - public function __construct($filters = array()) - { - foreach ($filters as $filter) { - $this->ensure($filter); - } - } - - /** - * Checks that the current collection contains the supplied filter. - * - * If the supplied filter is another filter collection, each of its - * filters will be checked. - */ - public function ensure(FilterInterface $filter) - { - if ($filter instanceof \Traversable) { - foreach ($filter as $f) { - $this->ensure($f); - } - } elseif (!in_array($filter, $this->filters, true)) { - $this->filters[] = $filter; - } - } - - public function all() - { - return $this->filters; - } - - public function clear() - { - $this->filters = array(); - } - - public function filterLoad(AssetInterface $asset) - { - foreach ($this->filters as $filter) { - $filter->filterLoad($asset); - } - } - - public function filterDump(AssetInterface $asset) - { - foreach ($this->filters as $filter) { - $filter->filterDump($asset); - } - } - - public function getIterator(): Traversable - { - return new \ArrayIterator($this->filters); - } - - public function count(): int - { - return count($this->filters); - } -} diff --git a/src/Assetic/Filter/FilterInterface.php b/src/Assetic/Filter/FilterInterface.php deleted file mode 100644 index 1714a8ad8..000000000 --- a/src/Assetic/Filter/FilterInterface.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ -interface FilterInterface -{ - /** - * Filters an asset after it has been loaded. - * - * @param AssetInterface $asset An asset - */ - public function filterLoad(AssetInterface $asset); - - /** - * Filters an asset just before it's dumped. - * - * @param AssetInterface $asset An asset - */ - public function filterDump(AssetInterface $asset); -} diff --git a/src/Assetic/Filter/HashableInterface.php b/src/Assetic/Filter/HashableInterface.php deleted file mode 100644 index 88149450a..000000000 --- a/src/Assetic/Filter/HashableInterface.php +++ /dev/null @@ -1,25 +0,0 @@ - - */ -interface HashableInterface -{ - /** - * Generates a hash for the object - * - * @return string Object hash - */ - public function hash(); -} diff --git a/src/Assetic/Filter/JSMinFilter.php b/src/Assetic/Filter/JSMinFilter.php deleted file mode 100644 index b2b245625..000000000 --- a/src/Assetic/Filter/JSMinFilter.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -class JSMinFilter implements FilterInterface -{ - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $asset->setContent(\JSMin::minify($asset->getContent())); - } -} diff --git a/src/Assetic/Filter/JSMinPlusFilter.php b/src/Assetic/Filter/JSMinPlusFilter.php deleted file mode 100644 index 2fcf92e9b..000000000 --- a/src/Assetic/Filter/JSMinPlusFilter.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -class JSMinPlusFilter implements FilterInterface -{ - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $asset->setContent(\JSMinPlus::minify($asset->getContent())); - } -} diff --git a/src/Assetic/Filter/JSqueezeFilter.php b/src/Assetic/Filter/JSqueezeFilter.php deleted file mode 100644 index 5a2127ac3..000000000 --- a/src/Assetic/Filter/JSqueezeFilter.php +++ /dev/null @@ -1,75 +0,0 @@ - - */ -class JSqueezeFilter implements FilterInterface -{ - private $singleLine = true; - private $keepImportantComments = true; - private $className; - private $specialVarRx = false; - private $defaultRx; - - public function __construct() - { - // JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x - if (class_exists('\\Patchwork\\JSqueeze')) { - $this->className = '\\Patchwork\\JSqueeze'; - $this->defaultRx = \Patchwork\JSqueeze::SPECIAL_VAR_PACKER; - } else { - $this->className = '\\JSqueeze'; - $this->defaultRx = \JSqueeze::SPECIAL_VAR_RX; - } - } - - public function setSingleLine($bool) - { - $this->singleLine = (bool) $bool; - } - - // call setSpecialVarRx(true) to enable global var/method/property - // renaming with the default regex (for 1.x or 2.x) - public function setSpecialVarRx($specialVarRx) - { - if (true === $specialVarRx) { - $this->specialVarRx = $this->defaultRx; - } else { - $this->specialVarRx = $specialVarRx; - } - } - - public function keepImportantComments($bool) - { - $this->keepImportantComments = (bool) $bool; - } - - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $parser = new $this->className(); - $asset->setContent($parser->squeeze( - $asset->getContent(), - $this->singleLine, - $this->keepImportantComments, - $this->specialVarRx - )); - } -} diff --git a/src/Assetic/Filter/LessphpFilter.php b/src/Assetic/Filter/LessphpFilter.php deleted file mode 100644 index 2478517b0..000000000 --- a/src/Assetic/Filter/LessphpFilter.php +++ /dev/null @@ -1,165 +0,0 @@ - - * @author Kris Wallsmith - */ -class LessphpFilter implements DependencyExtractorInterface -{ - private $presets = array(); - private $formatter; - private $preserveComments; - private $customFunctions = array(); - private $options = array(); - - /** - * Lessphp Load Paths - * - * @var array - */ - protected $loadPaths = array(); - - /** - * Adds a load path to the paths used by lessphp - * - * @param string $path Load Path - */ - public function addLoadPath($path) - { - $this->loadPaths[] = $path; - } - - /** - * Sets load paths used by lessphp - * - * @param array $loadPaths Load paths - */ - public function setLoadPaths(array $loadPaths) - { - $this->loadPaths = $loadPaths; - } - - public function setPresets(array $presets) - { - $this->presets = $presets; - } - - public function setOptions(array $options) - { - $this->options = $options; - } - - /** - * @param string $formatter One of "lessjs", "compressed", or "classic". - */ - public function setFormatter($formatter) - { - $this->formatter = $formatter; - } - - /** - * @param boolean $preserveComments - */ - public function setPreserveComments($preserveComments) - { - $this->preserveComments = $preserveComments; - } - - public function filterLoad(AssetInterface $asset) - { - $lc = new \lessc(); - if ($dir = $asset->getSourceDirectory()) { - $lc->importDir = $dir; - } - - foreach ($this->loadPaths as $loadPath) { - $lc->addImportDir($loadPath); - } - - foreach ($this->customFunctions as $name => $callable) { - $lc->registerFunction($name, $callable); - } - - if ($this->formatter) { - $lc->setFormatter($this->formatter); - } - - if (null !== $this->preserveComments) { - $lc->setPreserveComments($this->preserveComments); - } - - if (method_exists($lc, 'setOptions') && count($this->options) > 0) { - $lc->setOptions($this->options); - } - - $asset->setContent($lc->parse($asset->getContent(), $this->presets)); - } - - public function registerFunction($name, $callable) - { - $this->customFunctions[$name] = $callable; - } - - public function filterDump(AssetInterface $asset) - { - } - - public function getChildren(AssetFactory $factory, $content, $loadPath = null) - { - $loadPaths = $this->loadPaths; - if (null !== $loadPath) { - $loadPaths[] = $loadPath; - } - - if (empty($loadPaths)) { - return array(); - } - - $children = array(); - foreach (LessUtils::extractImports($content) as $reference) { - if ('.css' === substr($reference, -4)) { - // skip normal css imports - // todo: skip imports with media queries - continue; - } - - if ('.less' !== substr($reference, -5)) { - $reference .= '.less'; - } - - foreach ($loadPaths as $loadPath) { - if (file_exists($file = $loadPath.'/'.$reference)) { - $coll = $factory->createAsset($file, array(), array('root' => $loadPath)); - foreach ($coll as $leaf) { - $leaf->ensureFilter($this); - $children[] = $leaf; - goto next_reference; - } - } - } - - next_reference: - } - - return $children; - } -} diff --git a/src/Assetic/Filter/MinifyCssCompressorFilter.php b/src/Assetic/Filter/MinifyCssCompressorFilter.php deleted file mode 100644 index acac575eb..000000000 --- a/src/Assetic/Filter/MinifyCssCompressorFilter.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @author http://code.google.com/u/1stvamp/ (Issue 64 patch) - */ -class MinifyCssCompressorFilter implements FilterInterface -{ - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $asset->setContent(\Minify_CSS_Compressor::process($asset->getContent())); - } -} diff --git a/src/Assetic/Filter/PackagerFilter.php b/src/Assetic/Filter/PackagerFilter.php deleted file mode 100644 index e65348f40..000000000 --- a/src/Assetic/Filter/PackagerFilter.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -class PackagerFilter implements FilterInterface -{ - private $packages; - - public function __construct(array $packages = array()) - { - $this->packages = $packages; - } - - public function addPackage($package) - { - $this->packages[] = $package; - } - - public function filterLoad(AssetInterface $asset) - { - static $manifest = <<getContent()); - - $packager = new \Packager(array_merge(array($package), $this->packages)); - $content = $packager->build(array(), array(), array('Application'.$hash)); - - unlink($package.'/package.yml'); - unlink($package.'/source.js'); - rmdir($package); - - $asset->setContent($content); - } - - public function filterDump(AssetInterface $asset) - { - } -} diff --git a/src/Assetic/Filter/PackerFilter.php b/src/Assetic/Filter/PackerFilter.php deleted file mode 100644 index b6dcc5aa8..000000000 --- a/src/Assetic/Filter/PackerFilter.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -class PackerFilter implements FilterInterface -{ - protected $encoding = 'None'; - - protected $fastDecode = true; - - protected $specialChars = false; - - public function setEncoding($encoding) - { - $this->encoding = $encoding; - } - - public function setFastDecode($fastDecode) - { - $this->fastDecode = (bool) $fastDecode; - } - - public function setSpecialChars($specialChars) - { - $this->specialChars = (bool) $specialChars; - } - - public function filterLoad(AssetInterface $asset) - { - } - - public function filterDump(AssetInterface $asset) - { - $packer = new \JavaScriptPacker($asset->getContent(), $this->encoding, $this->fastDecode, $this->specialChars); - $asset->setContent($packer->pack()); - } -} diff --git a/src/Assetic/Filter/ScssphpFilter.php b/src/Assetic/Filter/ScssphpFilter.php deleted file mode 100644 index c2cefeff9..000000000 --- a/src/Assetic/Filter/ScssphpFilter.php +++ /dev/null @@ -1,146 +0,0 @@ - - */ -class ScssphpFilter implements DependencyExtractorInterface -{ - private $compass = false; - private $importPaths = array(); - private $customFunctions = array(); - private $formatter; - private $variables = array(); - - public function enableCompass($enable = true) - { - $this->compass = (Boolean) $enable; - } - - public function isCompassEnabled() - { - return $this->compass; - } - - public function setFormatter($formatter) - { - $legacyFormatters = array( - 'scss_formatter' => 'ScssPhp\ScssPhp\Formatter\Expanded', - 'scss_formatter_nested' => 'ScssPhp\ScssPhp\Formatter\Nested', - 'scss_formatter_compressed' => 'ScssPhp\ScssPhp\Formatter\Compressed', - 'scss_formatter_crunched' => 'ScssPhp\ScssPhp\Formatter\Crunched', - ); - - if (isset($legacyFormatters[$formatter])) { - @trigger_error(sprintf('The scssphp formatter `%s` is deprecated. Use `%s` instead.', $formatter, $legacyFormatters[$formatter]), E_USER_DEPRECATED); - - $formatter = $legacyFormatters[$formatter]; - } - - $this->formatter = $formatter; - } - - public function setVariables(array $variables) - { - $this->variables = $variables; - } - - public function addVariable($variable) - { - $this->variables[] = $variable; - } - - public function setImportPaths(array $paths) - { - $this->importPaths = $paths; - } - - public function addImportPath($path) - { - $this->importPaths[] = $path; - } - - public function registerFunction($name, $callable) - { - $this->customFunctions[$name] = $callable; - } - - public function filterLoad(AssetInterface $asset) - { - $sc = new Compiler(); - - if ($this->compass) { - new \scss_compass($sc); - } - - if ($dir = $asset->getSourceDirectory()) { - $sc->addImportPath($dir); - } - - foreach ($this->importPaths as $path) { - $sc->addImportPath($path); - } - - foreach ($this->customFunctions as $name => $callable) { - $sc->registerFunction($name, $callable); - } - - if ($this->formatter) { - $sc->setFormatter($this->formatter); - } - - if (!empty($this->variables)) { - $sc->setVariables($this->variables); - } - - $asset->setContent($sc->compile($asset->getContent())); - } - - public function filterDump(AssetInterface $asset) - { - } - - public function getChildren(AssetFactory $factory, $content, $loadPath = null) - { - $sc = new Compiler(); - if ($loadPath !== null) { - $sc->addImportPath($loadPath); - } - - foreach ($this->importPaths as $path) { - $sc->addImportPath($path); - } - - $children = array(); - foreach (CssUtils::extractImports($content) as $match) { - $file = $sc->findImport($match); - if ($file) { - $children[] = $child = $factory->createAsset($file, [], ['root' => $loadPath]); - $child->load(); - $childLoadPath = $child->all()[0]->getSourceDirectory(); - $children = array_merge($children, $this->getChildren($factory, $child->getContent(), $childLoadPath)); - } - } - - return $children; - } -} diff --git a/src/Assetic/Filter/StylesheetMinify.php b/src/Assetic/Filter/StylesheetMinify.php deleted file mode 100644 index f8cd23c7b..000000000 --- a/src/Assetic/Filter/StylesheetMinify.php +++ /dev/null @@ -1,63 +0,0 @@ -setContent($this->minify($asset->getContent())); - } - - /** - * Minifies CSS - * @var $css string CSS code to minify. - * @return string Minified CSS. - */ - protected function minify($css) - { - // Normalize whitespace in a smart way - $css = preg_replace('/\s{2,}/', ' ', $css); - - // Remove spaces before and after comment - $css = preg_replace('/(\s+)(\/\*[^!](.*?)\*\/)(\s+)/', '$2', $css); - - // Remove comment blocks, everything between /* and */, ignore /*! comments - $css = preg_replace('#/\*[^\!].*?\*/#s', '', $css); - - // Remove ; before } - $css = preg_replace('/;(?=\s*})/', '', $css); - - // Remove space after , : ; { } */ >, but not after !*/ - $css = preg_replace('/(,|:|;|\{|}|[^!]\*\/|>) /', '$1', $css); - - // Remove space before , ; { } > - $css = preg_replace('/ (,|;|\{|}|>)/', '$1', $css); - - // Remove newline before } > - $css = preg_replace('/(\r\n|\r|\n)(})/', '$2', $css); - - // Remove trailing zeros from float numbers preceded by : or a white-space - // -6.0100em to -6.01em, .0100 to .01, 1.200px to 1.2px - $css = preg_replace('/((? - */ -class FilterManager -{ - private $filters = array(); - - public function set($alias, FilterInterface $filter) - { - $this->checkName($alias); - - $this->filters[$alias] = $filter; - } - - public function get($alias) - { - if (!isset($this->filters[$alias])) { - throw new \InvalidArgumentException(sprintf('There is no "%s" filter.', $alias)); - } - - return $this->filters[$alias]; - } - - public function has($alias) - { - return isset($this->filters[$alias]); - } - - public function getNames() - { - return array_keys($this->filters); - } - - /** - * Checks that a name is valid. - * - * @param string $name An asset name candidate - * - * @throws \InvalidArgumentException If the asset name is invalid - */ - protected function checkName($name) - { - if (!ctype_alnum(str_replace('_', '', $name))) { - throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $name)); - } - } -} diff --git a/src/Assetic/LICENSE b/src/Assetic/LICENSE deleted file mode 100644 index f5dedf447..000000000 --- a/src/Assetic/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2010-2015 OpenSky Project Inc - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is furnished -to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/src/Assetic/README.md b/src/Assetic/README.md deleted file mode 100644 index 2c98ad06c..000000000 --- a/src/Assetic/README.md +++ /dev/null @@ -1,346 +0,0 @@ -# Storm Assetic Resources - -These libraries are useful when parsing assets with the Assetic combiner. - -Assetic is an asset management framework for PHP. - -``` php -dump(); -``` - -Assets ------- - -An Assetic asset is something with filterable content that can be loaded and -dumped. An asset also includes metadata, some of which can be manipulated and -some of which is immutable. - -| **Property** | **Accessor** | **Mutator** | -|--------------|-----------------|---------------| -| content | getContent | setContent | -| mtime | getLastModified | n/a | -| source root | getSourceRoot | n/a | -| source path | getSourcePath | n/a | -| target path | getTargetPath | setTargetPath | - -The "target path" property denotes where an asset (or an collection of assets) should be dumped. - -Filters -------- - -Filters can be applied to manipulate assets. - -``` php -dump(); -``` - -The filters applied to the collection will cascade to each asset leaf if you -iterate over it. - -``` php -dump(); -} -``` - -The core provides the following filters in the `Assetic\Filter` namespace: - - * `AutoprefixerFilter`: Parse and update vendor-specific properties using autoprefixer - * `CoffeeScriptFilter`: compiles CoffeeScript into Javascript - * `CompassFilter`: Compass CSS authoring framework - * `CssEmbedFilter`: embeds image data in your stylesheets - * `CssImportFilter`: inlines imported stylesheets - * `CssMinFilter`: minifies CSS - * `CleanCssFilter`: minifies CSS - * `CssRewriteFilter`: fixes relative URLs in CSS assets when moving to a new URL - * `DartFilter`: compiles Javascript using dart2js - * `EmberPrecompileFilter`: precompiles Handlebars templates into Javascript for use in the Ember.js framework - * `GoogleClosure\CompilerApiFilter`: compiles Javascript using the Google Closure Compiler API - * `GoogleClosure\CompilerJarFilter`: compiles Javascript using the Google Closure Compiler JAR - * `GssFilter`: compliles CSS using the Google Closure Stylesheets Compiler - * `HandlebarsFilter`: compiles Handlebars templates into Javascript - * `JpegoptimFilter`: optimize your JPEGs - * `JpegtranFilter`: optimize your JPEGs - * `JSMinFilter`: minifies Javascript - * `JSMinPlusFilter`: minifies Javascript - * `JSqueezeFilter`: compresses Javascript - * `LessFilter`: parses LESS into CSS (using less.js with node.js) - * `LessphpFilter`: parses LESS into CSS (using lessphp) - * `OptiPngFilter`: optimize your PNGs - * `PackerFilter`: compresses Javascript using Dean Edwards's Packer - * `PhpCssEmbedFilter`: embeds image data in your stylesheet - * `PngoutFilter`: optimize your PNGs - * `ReactJsxFilter`: compiles React JSX into JavaScript - * `Sass\SassFilter`: parses SASS into CSS - * `Sass\ScssFilter`: parses SCSS into CSS - * `SassphpFilter`: parses Sass into CSS using the sassphp bindings for Libsass - * `ScssphpFilter`: parses SCSS using scssphp - * `SeparatorFilter`: inserts a separator between assets to prevent merge failures - * `SprocketsFilter`: Sprockets Javascript dependency management - * `StylusFilter`: parses STYL into CSS - * `TypeScriptFilter`: parses TypeScript into Javascript - * `UglifyCssFilter`: minifies CSS - * `UglifyJs2Filter`: minifies Javascript - * `UglifyJsFilter`: minifies Javascript - * `Yui\CssCompressorFilter`: compresses CSS using the YUI compressor - * `Yui\JsCompressorFilter`: compresses Javascript using the YUI compressor - -Asset Manager -------------- - -An asset manager is provided for organizing assets. - -``` php -set('jquery', new FileAsset('/path/to/jquery.js')); -$am->set('base_css', new GlobAsset('/path/to/css/*')); -``` - -The asset manager can also be used to reference assets to avoid duplication. - -``` php -set('my_plugin', new AssetCollection(array( - new AssetReference($am, 'jquery'), - new FileAsset('/path/to/jquery.plugin.js'), -))); -``` - -Filter Manager --------------- - -A filter manager is also provided for organizing filters. - -``` php -set('sass', new SassFilter('/path/to/parser/sass')); -$fm->set('yui_css', new Yui\CssCompressorFilter('/path/to/yuicompressor.jar')); -``` - -Asset Factory -------------- - -If you'd rather not create all these objects by hand, you can use the asset -factory, which will do most of the work for you. - -``` php -setAssetManager($am); -$factory->setFilterManager($fm); -$factory->setDebug(true); - -$css = $factory->createAsset(array( - '@reset', // load the asset manager's "reset" asset - 'css/src/*.scss', // load every scss files from "/path/to/asset/directory/css/src/" -), array( - 'scss', // filter through the filter manager's "scss" filter - '?yui_css', // don't use this filter in debug mode -)); - -echo $css->dump(); -``` - -The `AssetFactory` is constructed with a root directory which is used as the base directory for relative asset paths. - -Prefixing a filter name with a question mark, as `yui_css` is here, will cause -that filter to be omitted when the factory is in debug mode. - -You can also register [Workers](src/Assetic/Factory/Worker/WorkerInterface.php) on the factory and all assets created -by it will be passed to the worker's `process()` method before being returned. See _Cache Busting_ below for an example. - -Dumping Assets to static files ------------------------------- - -You can dump all the assets an AssetManager holds to files in a directory. This will probably be below your webserver's document root -so the files can be served statically. - -``` php -writeManagerAssets($am); -``` - -This will make use of the assets' target path. - -Cache Busting -------------- - -If you serve your assets from static files as just described, you can use the CacheBustingWorker to rewrite the target -paths for assets. It will insert an identifier before the filename extension that is unique for a particular version -of the asset. - -This identifier is based on the modification time of the asset and will also take depended-on assets into -consideration if the applied filters support it. - -``` php -setAssetManager($am); -$factory->setFilterManager($fm); -$factory->setDebug(true); -$factory->addWorker(new CacheBustingWorker()); - -$css = $factory->createAsset(array( - '@reset', // load the asset manager's "reset" asset - 'css/src/*.scss', // load every scss files from "/path/to/asset/directory/css/src/" -), array( - 'scss', // filter through the filter manager's "scss" filter - '?yui_css', // don't use this filter in debug mode -)); - -echo $css->dump(); -``` - -Internal caching -------- - -A simple caching mechanism is provided to avoid unnecessary work. - -``` php -dump(); -$js->dump(); -$js->dump(); -``` - -Twig ----- - -To use the Assetic [Twig][3] extension you must register it to your Twig -environment: - -``` php -addExtension(new AsseticExtension($factory)); -``` - -Once in place, the extension exposes a stylesheets and a javascripts tag with a syntax similar -to what the asset factory uses: - -``` html+jinja -{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %} - -{% endstylesheets %} -``` - -This example will render one `link` element on the page that includes a URL -where the filtered asset can be found. - -When the extension is in debug mode, this same tag will render multiple `link` -elements, one for each asset referenced by the `css/src/*.sass` glob. The -specified filters will still be applied, unless they are marked as optional -using the `?` prefix. - -This behavior can also be triggered by setting a `debug` attribute on the tag: - -``` html+jinja -{% stylesheets 'css/*' debug=true %} ... {% stylesheets %} -``` - -These assets need to be written to the web directory so these URLs don't -return 404 errors. - -``` php -setLoader('twig', new TwigFormulaLoader($twig)); - -// loop through all your templates -foreach ($templates as $template) { - $resource = new TwigResource($twigLoader, $template); - $am->addResource($resource, 'twig'); -} - -$writer = new AssetWriter('/path/to/web'); -$writer->writeManagerAssets($am); -``` - ---- - -Assetic is based on the Python [webassets][1] library (available on -[GitHub][2]). - -[1]: http://elsdoerfer.name/docs/webassets -[2]: https://github.com/miracle2k/webassets -[3]: http://twig.sensiolabs.org diff --git a/src/Assetic/Util/CssUtils.php b/src/Assetic/Util/CssUtils.php deleted file mode 100644 index 229914cde..000000000 --- a/src/Assetic/Util/CssUtils.php +++ /dev/null @@ -1,136 +0,0 @@ - - */ -abstract class CssUtils -{ - const REGEX_URLS = '/url\((["\']?)(?P.*?)(\\1)\)/'; - const REGEX_IMPORTS = '/@import (?:url\()?(\'|"|)(?P[^\'"\)\n\r]*)\1\)?;?/'; - const REGEX_IMPORTS_NO_URLS = '/@import (?!url\()(\'|"|)(?P[^\'"\)\n\r]*)\1;?/'; - const REGEX_IE_FILTERS = '/src=(["\']?)(?P.*?)\\1/'; - const REGEX_COMMENTS = '/(\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)/'; - - /** - * Filters all references -- url() and "@import" -- through a callable. - * - * @param string $content The CSS - * @param callable $callback A PHP callable - * - * @return string The filtered CSS - */ - public static function filterReferences($content, $callback) - { - $content = static::filterUrls($content, $callback); - $content = static::filterImports($content, $callback, false); - $content = static::filterIEFilters($content, $callback); - - return $content; - } - - /** - * Filters all CSS url()'s through a callable. - * - * @param string $content The CSS - * @param callable $callback A PHP callable - * - * @return string The filtered CSS - */ - public static function filterUrls($content, $callback) - { - $pattern = static::REGEX_URLS; - - return static::filterCommentless($content, function ($part) use (&$callback, $pattern) { - return preg_replace_callback($pattern, $callback, $part); - }); - } - - /** - * Filters all CSS imports through a callable. - * - * @param string $content The CSS - * @param callable $callback A PHP callable - * @param Boolean $includeUrl Whether to include url() in the pattern - * - * @return string The filtered CSS - */ - public static function filterImports($content, $callback, $includeUrl = true) - { - $pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS; - - return static::filterCommentless($content, function ($part) use (&$callback, $pattern) { - return preg_replace_callback($pattern, $callback, $part); - }); - } - - /** - * Filters all IE filters (AlphaImageLoader filter) through a callable. - * - * @param string $content The CSS - * @param callable $callback A PHP callable - * - * @return string The filtered CSS - */ - public static function filterIEFilters($content, $callback) - { - $pattern = static::REGEX_IE_FILTERS; - - return static::filterCommentless($content, function ($part) use (&$callback, $pattern) { - return preg_replace_callback($pattern, $callback, $part); - }); - } - - /** - * Filters each non-comment part through a callable. - * - * @param string $content The CSS - * @param callable $callback A PHP callable - * - * @return string The filtered CSS - */ - public static function filterCommentless($content, $callback) - { - $result = ''; - foreach (preg_split(static::REGEX_COMMENTS, $content, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) { - if (!preg_match(static::REGEX_COMMENTS, $part, $match) || $part != $match[0]) { - $part = call_user_func($callback, $part); - } - - $result .= $part; - } - - return $result; - } - - /** - * Extracts all references from the supplied CSS content. - * - * @param string $content The CSS content - * - * @return array An array of unique URLs - */ - public static function extractImports($content) - { - $imports = array(); - static::filterImports($content, function ($matches) use (&$imports) { - $imports[] = $matches['url']; - }); - - return array_unique(array_filter($imports)); - } - - final private function __construct() - { - } -} diff --git a/src/Assetic/Util/FilesystemUtils.php b/src/Assetic/Util/FilesystemUtils.php deleted file mode 100644 index bc8395a67..000000000 --- a/src/Assetic/Util/FilesystemUtils.php +++ /dev/null @@ -1,82 +0,0 @@ - - */ -class FilesystemUtils -{ - /** - * Recursively removes a directory from the filesystem. - */ - public static function removeDirectory($directory) - { - $inner = new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS); - $outer = new \RecursiveIteratorIterator($inner, \RecursiveIteratorIterator::SELF_FIRST); - - // remove the files first - foreach ($outer as $file) { - if ($file->isFile()) { - unlink($file); - } - } - - // remove the sub-directories next - $files = iterator_to_array($outer); - foreach (array_reverse($files) as $file) { - /** @var \SplFileInfo $file */ - if ($file->isDir()) { - rmdir($file); - } - } - - // finally the directory itself - rmdir($directory); - } - - /** - * Creates a throw-away directory. - * - * This is not considered a "temporary" directory because it will not be - * automatically deleted at the end of the request or process. It must be - * deleted manually. - * - * @param string $prefix A prefix for the directory name - * - * @return string The directory path - */ - public static function createThrowAwayDirectory($prefix) - { - $directory = self::getTemporaryDirectory().DIRECTORY_SEPARATOR.uniqid('assetic_'.$prefix); - mkdir($directory); - - return $directory; - } - - /** - * Creates a temporary file. - * - * @param string $prefix A prefix for the file name - * - * @return string The file path - */ - public static function createTemporaryFile($prefix) - { - return tempnam(self::getTemporaryDirectory(), 'assetic_'.$prefix); - } - - public static function getTemporaryDirectory() - { - return realpath(sys_get_temp_dir()); - } -} diff --git a/src/Assetic/Util/LessUtils.php b/src/Assetic/Util/LessUtils.php deleted file mode 100644 index 25f4574d0..000000000 --- a/src/Assetic/Util/LessUtils.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -abstract class LessUtils extends CssUtils -{ - const REGEX_IMPORTS = '/@import(?:-once)? (?:\([a-z]*\) )?(?:url\()?(\'|"|)(?P[^\'"\)\n\r]*)\1\)?;?/'; - const REGEX_IMPORTS_NO_URLS = '/@import(?:-once)? (?:\([a-z]*\) )?(?!url\()(\'|"|)(?P[^\'"\)\n\r]*)\1;?/'; - const REGEX_COMMENTS = '/((?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)|\/\/[^\n]+)/'; -} diff --git a/src/Assetic/Util/SassUtils.php b/src/Assetic/Util/SassUtils.php deleted file mode 100644 index 175221415..000000000 --- a/src/Assetic/Util/SassUtils.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -abstract class SassUtils extends CssUtils -{ - const REGEX_COMMENTS = '/((?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)|\/\/[^\n]+)/'; -} diff --git a/src/Assetic/Util/TraversableString.php b/src/Assetic/Util/TraversableString.php deleted file mode 100644 index 9d3ad99e9..000000000 --- a/src/Assetic/Util/TraversableString.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class TraversableString implements \IteratorAggregate, \Countable -{ - private $one; - private $many; - - public function __construct($one, array $many) - { - $this->one = $one; - $this->many = $many; - } - - public function getIterator(): Traversable - { - return new \ArrayIterator($this->many); - } - - public function count(): int - { - return count($this->many); - } - - public function __toString() - { - return (string) $this->one; - } -} diff --git a/src/Assetic/Util/VarUtils.php b/src/Assetic/Util/VarUtils.php deleted file mode 100644 index e3a3d2ea7..000000000 --- a/src/Assetic/Util/VarUtils.php +++ /dev/null @@ -1,82 +0,0 @@ - - */ -abstract class VarUtils -{ - /** - * Resolves variable placeholders. - * - * @param string $template A template string - * @param array $vars Variable names - * @param array $values Variable values - * - * @return string The resolved string - * - * @throws \InvalidArgumentException If there is a variable with no value - */ - public static function resolve($template, array $vars, array $values) - { - $map = array(); - foreach ($vars as $var) { - if (false === strpos($template, '{'.$var.'}')) { - continue; - } - - if (!isset($values[$var])) { - throw new \InvalidArgumentException(sprintf('The template "%s" contains the variable "%s", but was not given any value for it.', $template, $var)); - } - - $map['{'.$var.'}'] = $values[$var]; - } - - return strtr($template, $map); - } - - public static function getCombinations(array $vars, array $values) - { - if (!$vars) { - return array(array()); - } - - $combinations = array(); - $nbValues = array(); - foreach ($values as $var => $vals) { - if (!in_array($var, $vars, true)) { - continue; - } - - $nbValues[$var] = count($vals); - } - - for ($i = array_product($nbValues), $c = $i * 2; $i < $c; $i++) { - $k = $i; - $combination = array(); - - foreach ($vars as $var) { - $combination[$var] = $values[$var][$k % $nbValues[$var]]; - $k = intval($k / $nbValues[$var]); - } - - $combinations[] = $combination; - } - - return $combinations; - } - - final private function __construct() - { - } -} diff --git a/src/Console/Command.php b/src/Console/Command.php new file mode 100644 index 000000000..f1b117180 --- /dev/null +++ b/src/Console/Command.php @@ -0,0 +1,120 @@ + $longest) { + $longest = $length; + } + } + $innerLineWidth = $longest + $padding; + $width = $innerLineWidth + ($border * 2); + + // Top border + $this->comment(str_repeat('*', $width)); + + // Alert content + foreach ($lines as $line) { + // Apply padding and borders to each line + $this->comment( + str_repeat('*', $border) + . str_pad($line, $innerLineWidth, ' ', STR_PAD_BOTH) + . str_repeat('*', $border) + ); + } + + // Bottom border + $this->comment(str_repeat('*', $width)); + + $this->newLine(); + } + + /** + * Provide autocompletion for this command's input + */ + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void + { + $inputs = [ + 'arguments' => $input->getArguments(), + 'options' => $input->getOptions(), + ]; + + foreach ($inputs as $type => $data) { + switch ($type) { + case 'arguments': + $dataType = 'Argument'; + $suggestionType = 'Values'; + break; + case 'options': + $dataType = 'Option'; + $suggestionType = 'Options'; + break; + } + if (!empty($data)) { + foreach ($data as $name => $value) { + // Skip the command argument since that's handled by Artisan directly + if ( + $type === 'arguments' + && in_array($name, ['command']) + ) { + continue; + } + + $inputRoutingMethod = "mustSuggest{$dataType}ValuesFor"; + $suggestionValuesMethod = Str::camel('suggest ' . $name) . $suggestionType; + $suggestionsMethod = 'suggest' . $suggestionType; + + if ( + method_exists($this, $suggestionValuesMethod) + && $input->{$inputRoutingMethod}($name) + ) { + $values = $this->$suggestionValuesMethod($value, $inputs); + $suggestions->{$suggestionsMethod}($values); + } + } + } + } + } + + /** + * Example implementation of a suggestion method + */ + // public function suggestMyArgumentValues(string $value = null, array $allInput): array + // { + // if ($allInput['arguments']['dependent'] === 'matches') { + // return ['some', 'suggested', 'values']; + // } + // return ['all', 'values']; + // } +} diff --git a/src/Console/Traits/ConfirmsWithInput.php b/src/Console/Traits/ConfirmsWithInput.php new file mode 100644 index 000000000..8cc25d3e1 --- /dev/null +++ b/src/Console/Traits/ConfirmsWithInput.php @@ -0,0 +1,41 @@ +laravel->isProduction() && !$this->option('force')) { + $this->error("THE APPLICATION IS IN PRODUCTION"); + } + + $this->alert($message); + + $confirmed = false; + + if ($this->option('force')) { + $this->warn("The --force option was provided, proceeding without confirmation..."); + $confirmed = true; + } else { + $prompt = "Please type \"$requiredInput\" to proceed or CANCEL to cancel"; + do { + $input = $this->ask($prompt); + if (strtolower($input) === 'cancel') { + $confirmed = false; + break; + } + if (strtolower($input) === strtolower($requiredInput)) { + $confirmed = true; + } + } while ($confirmed === false); + } + + return $confirmed; + } +} diff --git a/src/Database/Updater.php b/src/Database/Updater.php index ea439d939..7ab557076 100644 --- a/src/Database/Updater.php +++ b/src/Database/Updater.php @@ -25,7 +25,7 @@ public function setUp($file) return false; } - $this->isValidScript($object); + $this->isValidScript($object, $file); Eloquent::unguard(); @@ -52,7 +52,7 @@ public function packDown($file) return false; } - $this->isValidScript($object); + $this->isValidScript($object, $file); Eloquent::unguard(); @@ -76,8 +76,11 @@ public function resolve($file) return; } - require_once $file; + $instance = require_once $file; + if (is_object($instance)) { + return $instance; + } if ($class = $this->getClassFromFile($file)) { return new $class; } @@ -86,7 +89,7 @@ public function resolve($file) /** * Checks if the object is a valid update script. */ - protected function isValidScript($object) + protected function isValidScript($object, $file) { if ($object instanceof Updates\Migration) { return true; @@ -96,8 +99,8 @@ protected function isValidScript($object) } throw new Exception(sprintf( - 'Database script [%s] must inherit Winter\Storm\Database\Updates\Migration or Winter\Storm\Database\Updates\Seeder classes', - get_class($object) + 'Database script [%s] must define a class that inherits the "Winter\Storm\Database\Updates\Migration" or "Winter\Storm\Database\Updates\Seeder" classes', + $file )); } diff --git a/src/Events/Dispatcher.php b/src/Events/Dispatcher.php index db5e9b934..5939fda3b 100644 --- a/src/Events/Dispatcher.php +++ b/src/Events/Dispatcher.php @@ -48,11 +48,10 @@ public function listen($events, $listener = null, $priority = 0) } elseif ($listener instanceof QueuedClosure) { $listener = $listener->resolve(); } - $listener = Serialization::wrapClosure($listener); foreach ((array) $events as $event) { if (Str::contains($event, '*')) { - $this->setupWildcardListen($event, $listener); + $this->setupWildcardListen($event, Serialization::wrapClosure($listener)); } else { $this->listeners[$event][$priority][] = $this->makeListener($listener); @@ -61,6 +60,20 @@ public function listen($events, $listener = null, $priority = 0) } } + /** + * Register an event listener with the dispatcher. + * + * @param \Closure|string|array $listener + * @param bool $wildcard + * @return \Closure + */ + public function makeListener($listener, $wildcard = false) + { + $listener = parent::makeListener($listener, $wildcard); + + return Serialization::wrapClosure($listener); + } + /** * Get the event that is currently firing. * @@ -127,9 +140,6 @@ public function dispatch($event, $payload = [], $halt = false) } foreach ($this->getListeners($event) as $listener) { - if ($listener instanceof SerializableClosure) { - $listener = $listener->getClosure(); - } $response = $listener($event, $payload); // If a response is returned from the listener and event halting is enabled diff --git a/src/Filesystem/FilesystemServiceProvider.php b/src/Filesystem/FilesystemServiceProvider.php index 11eab67a6..5a238fa0c 100644 --- a/src/Filesystem/FilesystemServiceProvider.php +++ b/src/Filesystem/FilesystemServiceProvider.php @@ -45,8 +45,9 @@ protected function registerNativeFilesystem() $files->filePermissions = $config->get('cms.defaultMask.file', null); $files->folderPermissions = $config->get('cms.defaultMask.folder', null); $files->pathSymbols = [ - '$' => base_path() . $config->get('cms.pluginsDir', '/plugins'), '~' => base_path(), + '$' => base_path() . $config->get('cms.pluginsDir', '/plugins'), + '#' => base_path() . $config->get('cms.themesDir', '/themes'), ]; return $files; }); diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index 88a880e49..44ae9719b 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -55,6 +55,16 @@ class Application extends ApplicationBase */ protected $mediaPath; + /** + * Get the version number of the application. + * + * @return string + */ + public function version() + { + return static::VERSION . ' - Winter CMS'; + } + /** * Get the path to the public / web directory. * diff --git a/src/Foundation/Providers/ArtisanServiceProvider.php b/src/Foundation/Providers/ArtisanServiceProvider.php index 04f758785..6f680fa27 100644 --- a/src/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Foundation/Providers/ArtisanServiceProvider.php @@ -13,7 +13,6 @@ class ArtisanServiceProvider extends ArtisanServiceProviderBase */ protected $commands = [ // Currently included in Winter - // @TODO: Assess for retention 'CacheClear' => \Illuminate\Cache\Console\ClearCommand::class, 'CacheForget' => \Illuminate\Cache\Console\ForgetCommand::class, 'ClearCompiled' => \Winter\Storm\Foundation\Console\ClearCompiledCommand::class, @@ -40,13 +39,10 @@ class ArtisanServiceProvider extends ArtisanServiceProviderBase 'RouteList' => \Illuminate\Foundation\Console\RouteListCommand::class, 'ScheduleFinish' => \Illuminate\Console\Scheduling\ScheduleFinishCommand::class, 'ScheduleRun' => \Illuminate\Console\Scheduling\ScheduleRunCommand::class, - 'Seed' => \Illuminate\Database\Console\Seeds\SeedCommand::class, - 'StorageLink' => \Illuminate\Foundation\Console\StorageLinkCommand::class, 'Up' => \Illuminate\Foundation\Console\UpCommand::class, 'ViewClear' => \Illuminate\Foundation\Console\ViewClearCommand::class, - - // Currently unsupported in Winter + // Currently unsupported in Winter: // @TODO: Assess for inclusion // 'ClearResets' => ClearResetsCommand::class, // 'Db' => DbCommand::class, @@ -63,6 +59,10 @@ class ArtisanServiceProvider extends ArtisanServiceProviderBase // 'ScheduleTest' => ScheduleTestCommand::class, // 'ScheduleWork' => ScheduleWorkCommand::class, // 'ViewCache' => ViewCacheCommand::class, + + // Explicitly unsupported in Winter: + // 'Seed' => \Illuminate\Database\Console\Seeds\SeedCommand::class, // Use `winter:up` instead + // 'StorageLink' => \Illuminate\Foundation\Console\StorageLinkCommand::class, // Use `winter:mirror` instead. ]; /** diff --git a/src/Halcyon/Processors/Processor.php b/src/Halcyon/Processors/Processor.php index 3253bfba1..fc6765fd7 100644 --- a/src/Halcyon/Processors/Processor.php +++ b/src/Halcyon/Processors/Processor.php @@ -58,7 +58,7 @@ protected function parseTemplateContent($query, $result, $fileName) 'isCompoundObject' => $query->getModel()->isCompoundObject() ]; - $content = array_get($result, 'content'); + $content = array_get($result, 'content', ''); $processed = SectionParser::parse($content, $options); diff --git a/src/Halcyon/Processors/SectionParser.php b/src/Halcyon/Processors/SectionParser.php index 16b839a38..f3dbadcdf 100644 --- a/src/Halcyon/Processors/SectionParser.php +++ b/src/Halcyon/Processors/SectionParser.php @@ -2,6 +2,7 @@ use Winter\Storm\Parse\Ini; use Winter\Storm\Support\Str; +use InvalidArgumentException; /** * This class parses CMS object files (pages, partials and layouts). @@ -15,25 +16,66 @@ class SectionParser const ERROR_INI = '_PARSER_ERROR_INI'; + /** + * Parse the provided content into sections + */ + protected static function parseIntoSections(string $content, int $limit = 3): array + { + $sections = preg_split('/^'.preg_quote(self::SECTION_SEPARATOR).'\s*$/m', $content, -1); + + // If more than the limit sections found, merge the extra sections into the final section + if ($limit >= 1 && count($sections) > $limit) { + // Break the content into lines + $lines = explode(PHP_EOL, $content); + $seperatorsSeen = 0; + + // Loop over the lines + foreach ($lines as $number => $line) { + // If we've seen $limit - 1 separators already then this is now the start of the final section + if ($seperatorsSeen === ($limit - 1)) { + break; + } + + // Check for a section separator on this line + if (trim($line) === static::SECTION_SEPARATOR) { + $seperatorsSeen++; + } + + // Remove this line from the result that will be merged into the final section + unset($lines[$number]); + } + + // Rebuild the sections array + $i = 0; + $originalSections = $sections; + $sections = []; + + for ($i = 0; $i < ($limit - 1); $i++) { + $sections[] = $originalSections[$i]; + } + $sections[] = implode(PHP_EOL, $lines); + } + + return $sections; + } + /** * Renders a CMS object as file content. - * @return string + * @throws InvalidArgumentException if section separators are found in the settings or code sections */ - public static function render($data, $options = []) + public static function render(array $data, array $options = []): string { extract(array_merge([ 'wrapCodeInPhpTags' => true, - 'isCompoundObject' => true + 'isCompoundObject' => true, ], $options)); if (!$isCompoundObject) { - return array_get($data, 'content'); + return array_get($data, 'content', ''); } + // Prepare settings section for saving $iniParser = new Ini; - $code = trim(array_get($data, 'code')); - $markup = trim(array_get($data, 'markup')); - $trim = function (&$values) use (&$trim) { foreach ($values as &$value) { if (!is_array($value)) { @@ -44,68 +86,117 @@ public static function render($data, $options = []) } } }; - $settings = array_get($data, 'settings', []); $trim($settings); + $settings = $iniParser->render($settings); - /* - * Build content - */ - $content = []; - - if ($settings) { - $content[] = $iniParser->render($settings); - } - + // Prepare code section for saving + $code = trim(array_get($data, 'code', '')); if ($code) { if ($wrapCodeInPhpTags) { $code = preg_replace('/^\<\?php/', '', $code); $code = preg_replace('/^\<\?/', '', $code); $code = preg_replace('/\?>$/', '', $code); $code = trim($code, PHP_EOL); + $code = ''; + } else { + $code = $code; + } + } + + // Prepare markup section for saving + $markup = trim(array_get($data, 'markup', '')); + + /* + * Build content + * + * One element = Markup + * Two elements = Settings, Markup + * Three Elements = Settings, Code, Markup + */ + $content = []; + $sections = 1; - $content[] = ''; + /** + * If markup contains a section separator all sections must be present + * in order to prevent any of the markup content being interpreted as + * anything else. + */ + if (count(static::parseIntoSections($markup, 0)) > 1) { + $sections = 3; + } else { + if (!empty($settings)) { + $sections = 2; } - else { - $content[] = $code; + if (!empty($code)) { + $sections = 3; } } - $content[] = $markup; + // Validate the settings section + if ( + !empty($settings) + && count(static::parseIntoSections($settings, 0)) > 1 + ) { + throw new InvalidArgumentException("The settings section cannot be rendered because it contains a section separator"); + } + + // Validate the code section + if ( + !empty($code) + && count(static::parseIntoSections($code, 0)) > 1 + ) { + throw new InvalidArgumentException("The code section cannot be rendered because it contains a section separator"); + } + + switch ($sections) { + case 1: + $content[] = $markup; + break; + case 2: + $content[] = $settings; + $content[] = $markup; + break; + case 3: + $content[] = $settings; + $content[] = $code; + $content[] = $markup; + break; + default: + throw new \Exception("Invalid number of sections $sections"); + } - $content = trim(implode(PHP_EOL.self::SECTION_SEPARATOR.PHP_EOL, $content)); + $content = trim(implode(PHP_EOL . self::SECTION_SEPARATOR . PHP_EOL, $content)); return $content; } /** - * Parses a CMS object file content. + * Parses Halcyon section content. * The expected file format is following: - *
-     * INI settings section
-     * ==
-     * PHP code section
-     * ==
-     * Twig markup section
-     * 
- * If the content has only 2 sections they are considered as settings and Twig. - * If there is only a single section, it is considered as Twig. - * @param string $content Specifies the file content. - * @return array Returns an array with the following indexes: 'settings', 'markup', 'code'. - * The 'markup' and 'code' elements contain strings. The 'settings' element contains the - * parsed INI file as array. If the content string doesn't contain a section, the corresponding - * result element has null value. + * + * INI settings section + * == + * PHP code section + * == + * Twig markup section + * + * If the content has only 2 sections they are parsed as settings and markup. + * If there is only a single section, it is parsed as markup. + * + * Returns an array with the following elements: (array|null) 'settings', + * (string|null) 'markup', (string|null) 'code'. */ - public static function parse($content, $options = []) + public static function parse(string $content, array $options = []): array { extract(array_merge([ - 'isCompoundObject' => true + 'isCompoundObject' => true, ], $options)); $result = [ 'settings' => [], 'code' => null, - 'markup' => null + 'markup' => null, ]; if (!$isCompoundObject || !strlen($content)) { @@ -113,7 +204,7 @@ public static function parse($content, $options = []) } $iniParser = new Ini; - $sections = preg_split('/^'.preg_quote(self::SECTION_SEPARATOR).'\s*$/m', $content, -1); + $sections = static::parseIntoSections($content); $count = count($sections); foreach ($sections as &$section) { $section = trim($section); @@ -130,14 +221,12 @@ public static function parse($content, $options = []) $result['code'] = trim($result['code'], PHP_EOL); $result['markup'] = $sections[2]; - } - elseif ($count == 2) { + } elseif ($count == 2) { $result['settings'] = @$iniParser->parse($sections[0], true) ?: [self::ERROR_INI => $sections[0]]; $result['markup'] = $sections[1]; - } - elseif ($count == 1) { + } elseif ($count == 1) { $result['markup'] = $sections[0]; } @@ -147,31 +236,30 @@ public static function parse($content, $options = []) /** * Same as parse method, except the line number where the respective section * begins is returned. - * @param string $content Specifies the file content. - * @return array Returns an array with the following indexes: 'settings', 'markup', 'code'. + * + * Returns an array with the following elements: (integer|null) 'settings', + * (integer|null) 'markup', (integer|null) 'code'. */ - public static function parseOffset($content) + public static function parseOffset(string $content): array { $content = Str::normalizeEol($content); - $sections = preg_split('/^'.preg_quote(self::SECTION_SEPARATOR).'\s*$/m', $content, -1); + $sections = static::parseIntoSections($content); $count = count($sections); $result = [ 'settings' => null, 'code' => null, - 'markup' => null + 'markup' => null, ]; if ($count >= 3) { $result['settings'] = self::adjustLinePosition($content); $result['code'] = self::calculateLinePosition($content); $result['markup'] = self::calculateLinePosition($content, 2); - } - elseif ($count == 2) { + } elseif ($count == 2) { $result['settings'] = self::adjustLinePosition($content); $result['markup'] = self::calculateLinePosition($content); - } - elseif ($count == 1) { + } elseif ($count == 1) { $result['markup'] = 1; } @@ -179,12 +267,9 @@ public static function parseOffset($content) } /** - * Returns the line number of a found instance of CMS object section separator (==). - * @param string $content Object content - * @param int $instance Which instance to look for - * @return int The line number the instance was found. + * Returns the line number of a found instance of a section separator (==). */ - private static function calculateLinePosition($content, $instance = 1) + private static function calculateLinePosition(string $content, int $instance = 1): int { $count = 0; $lines = explode(PHP_EOL, $content); @@ -205,11 +290,8 @@ private static function calculateLinePosition($content, $instance = 1) * Pushes the starting line number forward since it is not always directly * after the separator (==). There can be an opening tag or white space in between * where the section really begins. - * @param string $content Object content - * @param int $startLine The calculated starting line from calculateLinePosition() - * @return int The adjusted line number. */ - private static function adjustLinePosition($content, $startLine = -1) + private static function adjustLinePosition(string $content, int $startLine = -1): int { // Account for the separator itself. $startLine++; diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php index bf769090b..88cb6390e 100644 --- a/src/Mail/Mailer.php +++ b/src/Mail/Mailer.php @@ -5,6 +5,7 @@ use Illuminate\Mail\Mailer as MailerBase; use Illuminate\Contracts\Mail\Mailable as MailableContract; use Illuminate\Support\Collection; +use Illuminate\Mail\SentMessage; /** * Mailer class for sending mail. @@ -144,6 +145,8 @@ public function send($view, array $data = [], $callback = null) return; } + + // Next we will determine if the message should be sent. We give the developer // one final chance to stop this message and then we will send it to all of // its recipients. We will then fire the sent event for the sent message. @@ -151,34 +154,36 @@ public function send($view, array $data = [], $callback = null) $sentMessage = null; if ($this->shouldSendMessage($symfonyMessage, $data)) { - $sentMessage = $this->sendSymfonyMessage($symfonyMessage); - - $this->dispatchSentEvent($message, $data); - - $sentMessage = new SentMessage($sentMessage); - - /** - * @event mailer.send - * Fires after the message has been sent - * - * Example usage (logs the message): - * - * Event::listen('mailer.send', function ((\Winter\Storm\Mail\Mailer) $mailerInstance, (string) $view, (\Illuminate\Mail\Message) $message, (array) $data) { - * \Log::info("Message was rendered with $view and sent"); - * }); - * - * Or - * - * $mailerInstance->bindEvent('mailer.send', function ((string) $view, (\Illuminate\Mail\Message) $message, (array) $data) { - * \Log::info("Message was rendered with $view and sent"); - * }); - * - */ - $this->fireEvent('mailer.send', [$view, $message, $data]); - Event::fire('mailer.send', [$this, $view, $message, $data]); + $symfonySentMessage = $this->sendSymfonyMessage($symfonyMessage); + + if ($symfonySentMessage) { + $sentMessage = new SentMessage($symfonySentMessage); + + $this->dispatchSentEvent($sentMessage, $data); + + /** + * @event mailer.send + * Fires after the message has been sent + * + * Example usage (logs the message): + * + * Event::listen('mailer.send', function ((\Winter\Storm\Mail\Mailer) $mailerInstance, (string) $view, (\Illuminate\Mail\Message) $message, (array) $data) { + * \Log::info("Message was rendered with $view and sent"); + * }); + * + * Or + * + * $mailerInstance->bindEvent('mailer.send', function ((string) $view, (\Illuminate\Mail\Message) $message, (array) $data) { + * \Log::info("Message was rendered with $view and sent"); + * }); + * + */ + $this->fireEvent('mailer.send', [$view, $message, $data]); + Event::fire('mailer.send', [$this, $view, $message, $data]); + + return $sentMessage; + } } - - return $sentMessage; } /** @@ -510,10 +515,10 @@ protected function processRecipients($recipients) public function pretend($value = true) { if ($value) { - $this->pretendingOriginal = Config::get('mail.driver'); - Config::set('mail.driver', 'log'); + $this->pretendingOriginal = Config::get('mail.default', 'smtp'); + Config::set('mail.default', 'log'); } else { - Config::set('mail.driver', $this->pretendingOriginal); + Config::set('mail.default', $this->pretendingOriginal); } } } diff --git a/src/Parse/Assetic/Cache/FilesystemCache.php b/src/Parse/Assetic/Cache/FilesystemCache.php new file mode 100644 index 000000000..ea6a85a08 --- /dev/null +++ b/src/Parse/Assetic/Cache/FilesystemCache.php @@ -0,0 +1,29 @@ +dir) && false === @mkdir($this->dir, 0777, true)) { + throw new RuntimeException('Unable to create directory '.$this->dir); + } + + $path = $this->dir.'/'.$key; + + if (false === @file_put_contents($path, $value)) { + throw new RuntimeException('Unable to write file '.$path); + } + + File::chmod($path); + } +} diff --git a/src/Assetic/Filter/JavascriptImporter.php b/src/Parse/Assetic/Filter/JavascriptImporter.php similarity index 94% rename from src/Assetic/Filter/JavascriptImporter.php rename to src/Parse/Assetic/Filter/JavascriptImporter.php index c345132f7..56fff3060 100644 --- a/src/Assetic/Filter/JavascriptImporter.php +++ b/src/Parse/Assetic/Filter/JavascriptImporter.php @@ -1,9 +1,9 @@ -scriptPath = dirname($asset->getSourceRoot() . '/' . $asset->getSourcePath()); diff --git a/src/Assetic/Filter/LessCompiler.php b/src/Parse/Assetic/Filter/LessCompiler.php similarity index 77% rename from src/Assetic/Filter/LessCompiler.php rename to src/Parse/Assetic/Filter/LessCompiler.php index 828000bbb..f8fbd1cd2 100644 --- a/src/Assetic/Filter/LessCompiler.php +++ b/src/Parse/Assetic/Filter/LessCompiler.php @@ -1,21 +1,22 @@ -setContent($parser->getCss()); } - public function filterDump(AssetInterface $asset) - { - } - public function hashAsset($asset, $localPath) { $factory = new AssetFactory($localPath); diff --git a/src/Assetic/Filter/ScssCompiler.php b/src/Parse/Assetic/Filter/ScssCompiler.php similarity index 80% rename from src/Assetic/Filter/ScssCompiler.php rename to src/Parse/Assetic/Filter/ScssCompiler.php index 7bca60637..fdd563197 100644 --- a/src/Assetic/Filter/ScssCompiler.php +++ b/src/Parse/Assetic/Filter/ScssCompiler.php @@ -1,16 +1,15 @@ - 20, @@ -84,13 +80,23 @@ public function render($vars = [], $options = []) 'objectSupport' => true, ], $options)); + $flags = null; + + if ($exceptionOnInvalidType) { + $flags |= YamlComponent::DUMP_EXCEPTION_ON_INVALID_TYPE; + } + + if ($objectSupport) { + $flags |= YamlComponent::DUMP_OBJECT; + } + $yaml = new Dumper; if (!is_null($this->processor) && method_exists($this->processor, 'prerender')) { $vars = $this->processor->prerender($vars); } - $yamlContent = $yaml->dump($vars, $inline, 0, $exceptionOnInvalidType, $objectSupport); + $yamlContent = $yaml->dump($vars, $inline, 0, $flags); if (!is_null($this->processor) && method_exists($this->processor, 'render')) { $yamlContent = $this->processor->render($yamlContent); diff --git a/src/Scaffold/Console/CreateCommand.php b/src/Scaffold/Console/CreateCommand.php deleted file mode 100644 index 401ecaadf..000000000 --- a/src/Scaffold/Console/CreateCommand.php +++ /dev/null @@ -1,67 +0,0 @@ -(eg: Winter.Blog)} - {command : The name of the command to generate. (eg: create)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new console command.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Command'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'command/command.stub' => 'console/{{studly_name}}.php', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - $command = $this->argument('command'); - - return [ - 'name' => $command, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateComponent.php b/src/Scaffold/Console/CreateComponent.php deleted file mode 100644 index 67ffe3b6a..000000000 --- a/src/Scaffold/Console/CreateComponent.php +++ /dev/null @@ -1,68 +0,0 @@ -(eg: Winter.Blog)} - {component : The name of the component to generate. (eg: Posts)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new plugin component.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Component'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'component/component.stub' => 'components/{{studly_name}}.php', - 'component/default.stub' => 'components/{{lower_name}}/default.htm', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - $component = $this->argument('component'); - - return [ - 'name' => $component, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateController.php b/src/Scaffold/Console/CreateController.php deleted file mode 100644 index 81cb8c219..000000000 --- a/src/Scaffold/Console/CreateController.php +++ /dev/null @@ -1,87 +0,0 @@ -(eg: Winter.Blog)} - {controller : The name of the controller to generate. (eg: Posts)} - {--force : Overwrite existing files with generated files.} - {--model= : Defines the model name to use. If not provided, the singular name of the controller is used.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new controller.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Controller'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'controller/_list_toolbar.stub' => 'controllers/{{lower_name}}/_list_toolbar.htm', - 'controller/config_form.stub' => 'controllers/{{lower_name}}/config_form.yaml', - 'controller/config_list.stub' => 'controllers/{{lower_name}}/config_list.yaml', - 'controller/create.stub' => 'controllers/{{lower_name}}/create.htm', - 'controller/index.stub' => 'controllers/{{lower_name}}/index.htm', - 'controller/preview.stub' => 'controllers/{{lower_name}}/preview.htm', - 'controller/update.stub' => 'controllers/{{lower_name}}/update.htm', - 'controller/controller.stub' => 'controllers/{{studly_name}}.php', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - - $controller = $this->argument('controller'); - - /* - * Determine the model name to use, - * either supplied or singular from the controller name. - */ - $model = $this->option('model'); - if (!$model) { - $model = Str::singular($controller); - } - - return [ - 'name' => $controller, - 'model' => $model, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateFormWidget.php b/src/Scaffold/Console/CreateFormWidget.php deleted file mode 100644 index 75b42e3e7..000000000 --- a/src/Scaffold/Console/CreateFormWidget.php +++ /dev/null @@ -1,71 +0,0 @@ -(eg: Winter.Blog)} - {widget : The name of the form widget to generate. (eg: PostList)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new form widget.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'FormWidget'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'formwidget/formwidget.stub' => 'formwidgets/{{studly_name}}.php', - 'formwidget/partial.stub' => 'formwidgets/{{lower_name}}/partials/_{{lower_name}}.htm', - 'formwidget/stylesheet.stub' => 'formwidgets/{{lower_name}}/assets/css/{{lower_name}}.css', - 'formwidget/javascript.stub' => 'formwidgets/{{lower_name}}/assets/js/{{lower_name}}.js', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - - $widget = $this->argument('widget'); - - return [ - 'name' => $widget, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateModel.php b/src/Scaffold/Console/CreateModel.php deleted file mode 100644 index b4dcef7f0..000000000 --- a/src/Scaffold/Console/CreateModel.php +++ /dev/null @@ -1,71 +0,0 @@ -(eg: Winter.Blog)} - {model : The name of the model to generate. (eg: Post)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new model.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Model'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'model/model.stub' => 'models/{{studly_name}}.php', - 'model/fields.stub' => 'models/{{lower_name}}/fields.yaml', - 'model/columns.stub' => 'models/{{lower_name}}/columns.yaml', - 'model/create_table.stub' => 'updates/create_{{snake_plural_name}}_table.php', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - - $model = $this->argument('model'); - - return [ - 'name' => $model, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php deleted file mode 100644 index a17bc128c..000000000 --- a/src/Scaffold/Console/CreatePlugin.php +++ /dev/null @@ -1,75 +0,0 @@ -(eg: Winter.Blog)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new plugin.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Plugin'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'plugin/plugin.stub' => 'Plugin.php', - 'plugin/version.stub' => 'updates/version.yaml', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - /* - * Extract the author and name from the plugin code - */ - $pluginCode = $this->argument('plugin'); - $parts = explode('.', $pluginCode); - - if (count($parts) != 2) { - $this->error('Invalid plugin name, either too many dots or not enough.'); - $this->error('Example name: AuthorName.PluginName'); - return; - } - - - $pluginName = array_pop($parts); - $authorName = array_pop($parts); - - return [ - 'name' => $pluginName, - 'author' => $authorName, - ]; - } -} diff --git a/src/Scaffold/Console/CreateReportWidget.php b/src/Scaffold/Console/CreateReportWidget.php deleted file mode 100644 index 15c9dcf03..000000000 --- a/src/Scaffold/Console/CreateReportWidget.php +++ /dev/null @@ -1,69 +0,0 @@ -(eg: Winter.Blog)} - {widget : The name of the report widget to generate. (eg: PostViews)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new report widget.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'ReportWidget'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'reportwidget/reportwidget.stub' => 'reportwidgets/{{studly_name}}.php', - 'reportwidget/widget.stub' => 'reportwidgets/{{lower_name}}/partials/_{{lower_name}}.htm', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - - $widget = $this->argument('widget'); - - return [ - 'name' => $widget, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateSettings.php b/src/Scaffold/Console/CreateSettings.php deleted file mode 100644 index 25a752c3b..000000000 --- a/src/Scaffold/Console/CreateSettings.php +++ /dev/null @@ -1,68 +0,0 @@ -(eg: Winter.Blog)} - {settings : The name of the settings model to generate. (eg: BlogSettings)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new settings model.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Settings Model'; - - /** - * A mapping of stubs to generated files. - * - * @var array - */ - protected $stubs = [ - 'settings/model.stub' => 'models/{{studly_name}}.php', - 'settings/fields.stub' => 'models/{{lower_name}}/fields.yaml' - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - $pluginCode = $this->argument('plugin'); - - $parts = explode('.', $pluginCode); - $plugin = array_pop($parts); - $author = array_pop($parts); - $settings = $this->argument('settings') ?? 'Settings'; - - return [ - 'name' => $settings, - 'author' => $author, - 'plugin' => $plugin - ]; - } -} diff --git a/src/Scaffold/Console/CreateTheme.php b/src/Scaffold/Console/CreateTheme.php deleted file mode 100644 index 9a8672940..000000000 --- a/src/Scaffold/Console/CreateTheme.php +++ /dev/null @@ -1,121 +0,0 @@ -(eg: MyTheme)} - {--force : Overwrite existing files with generated files.}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Creates a new theme.'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Theme'; - - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'theme/assets/js/app.stub' => 'assets/js/app.js', - 'theme/assets/less/theme.stub' => 'assets/less/theme.less', - 'theme/layouts/default.stub' => 'layouts/default.htm', - 'theme/pages/404.stub' => 'pages/404.htm', - 'theme/pages/error.stub' => 'pages/error.htm', - 'theme/pages/home.stub' => 'pages/home.htm', - 'theme/partials/meta/seo.stub' => 'partials/meta/seo.htm', - 'theme/partials/meta/styles.stub' => 'partials/meta/styles.htm', - 'theme/partials/site/header.stub' => 'partials/site/header.htm', - 'theme/partials/site/footer.stub' => 'partials/site/footer.htm', - 'theme/theme.stub' => 'theme.yaml', - 'theme/version.stub' => 'version.yaml', - ]; - - /** - * Prepare variables for stubs. - * - * return @array - */ - protected function prepareVars() - { - /* - * Extract the author and name from the plugin code - */ - $code = str_slug($this->argument('theme')); - - return [ - 'code' => $code, - ]; - } - - /** - * Get the plugin path from the input. - * - * @return string - */ - protected function getDestinationPath() - { - $code = $this->prepareVars()['code']; - - return themes_path($code); - } - - /** - * Make a single stub. - * - * @param string $stubName The source filename for the stub. - */ - public function makeStub($stubName) - { - if (!isset($this->stubs[$stubName])) { - return; - } - - $sourceFile = $this->getSourcePath() . '/' . $stubName; - $destinationFile = $this->getDestinationPath() . '/' . $this->stubs[$stubName]; - $destinationContent = $this->files->get($sourceFile); - - /* - * Parse each variable in to the destination content and path - */ - foreach ($this->vars as $key => $var) { - $destinationContent = str_replace('{{' . $key . '}}', $var, $destinationContent); - $destinationFile = str_replace('{{' . $key . '}}', $var, $destinationFile); - } - - $this->makeDirectory($destinationFile); - - /* - * Make sure this file does not already exist - */ - if ($this->files->exists($destinationFile) && !$this->option('force')) { - throw new Exception('Stop everything!!! This file already exists: ' . $destinationFile); - } - - $this->files->put($destinationFile, $destinationContent); - } -} diff --git a/src/Scaffold/Console/command/command.stub b/src/Scaffold/Console/command/command.stub deleted file mode 100644 index bf65b244b..000000000 --- a/src/Scaffold/Console/command/command.stub +++ /dev/null @@ -1,63 +0,0 @@ -output->writeln('Hello world!'); - } - - /** - * Get the console command arguments. - * @return array - */ - protected function getArguments() - { - return []; - } - - /** - * Get the console command options. - * @return array - */ - protected function getOptions() - { - return []; - } - - /** - * Provide autocompletion for this command's input - */ - public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void - { - // Suggest values for arguments provided by this command - // if ($input->mustSuggestArgumentValuesFor('nameOfArgument')) { - // $suggestions->suggestValues(['valid', 'argument', 'values', 'here']]); - // } - - // Suggest values for options provided by this command - // if ($input->mustSuggestOptionValuesFor('nameOfOption')) { - // $suggestions->suggestValues(['valid', 'option', 'values', 'here']); - // } - } -} diff --git a/src/Scaffold/Console/component/component.stub b/src/Scaffold/Console/component/component.stub deleted file mode 100644 index 5f9bbbb7b..000000000 --- a/src/Scaffold/Console/component/component.stub +++ /dev/null @@ -1,19 +0,0 @@ - '{{name}} Component', - 'description' => 'No description provided yet...' - ]; - } - - public function defineProperties() - { - return []; - } -} diff --git a/src/Scaffold/Console/component/default.stub b/src/Scaffold/Console/component/default.stub deleted file mode 100644 index c9069b375..000000000 --- a/src/Scaffold/Console/component/default.stub +++ /dev/null @@ -1,3 +0,0 @@ -

This is the default markup for component {{name}}

- -You can delete this file if you want diff --git a/src/Scaffold/Console/controller/_list_toolbar.stub b/src/Scaffold/Console/controller/_list_toolbar.stub deleted file mode 100644 index 839d45651..000000000 --- a/src/Scaffold/Console/controller/_list_toolbar.stub +++ /dev/null @@ -1,21 +0,0 @@ -
- - New {{title_singular_name}} - - - -
diff --git a/src/Scaffold/Console/controller/config_form.stub b/src/Scaffold/Console/controller/config_form.stub deleted file mode 100644 index f5b0f4fe5..000000000 --- a/src/Scaffold/Console/controller/config_form.stub +++ /dev/null @@ -1,31 +0,0 @@ -# =================================== -# Form Behavior Config -# =================================== - -# Record name -name: {{title_singular_name}} - -# Model Form Field configuration -form: $/{{lower_author}}/{{lower_plugin}}/models/{{lower_model}}/fields.yaml - -# Model Class name -modelClass: {{studly_author}}\{{studly_plugin}}\Models\{{studly_model}} - -# Default redirect location -defaultRedirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}} - -# Create page -create: - title: backend::lang.form.create_title - redirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}}/update/:id - redirectClose: {{lower_author}}/{{lower_plugin}}/{{lower_name}} - -# Update page -update: - title: backend::lang.form.update_title - redirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}} - redirectClose: {{lower_author}}/{{lower_plugin}}/{{lower_name}} - -# Preview page -preview: - title: backend::lang.form.preview_title diff --git a/src/Scaffold/Console/controller/config_list.stub b/src/Scaffold/Console/controller/config_list.stub deleted file mode 100644 index 6ffce9b3d..000000000 --- a/src/Scaffold/Console/controller/config_list.stub +++ /dev/null @@ -1,50 +0,0 @@ -# =================================== -# List Behavior Config -# =================================== - -# Model List Column configuration -list: $/{{lower_author}}/{{lower_plugin}}/models/{{lower_model}}/columns.yaml - -# Model Class name -modelClass: {{studly_author}}\{{studly_plugin}}\Models\{{studly_model}} - -# List Title -title: Manage {{title_plural_name}} - -# Link URL for each record -recordUrl: {{lower_author}}/{{lower_plugin}}/{{lower_name}}/update/:id - -# Message to display if the list is empty -noRecordsMessage: backend::lang.list.no_records - -# Records to display per page -recordsPerPage: 20 - -# Options to provide the user when selecting how many records to display per page -perPageOptions: [20, 40, 80, 100, 120] - -# Display page numbers with pagination, disable to improve performance -showPageNumbers: true - -# Displays the list column set up button -showSetup: true - -# Displays the sorting link on each column -showSorting: true - -# Default sorting column -# defaultSort: -# column: created_at -# direction: desc - -# Display checkboxes next to each record -showCheckboxes: true - -# Toolbar widget configuration -toolbar: - # Partial for toolbar buttons - buttons: list_toolbar - - # Search widget configuration - search: - prompt: backend::lang.list.search_prompt diff --git a/src/Scaffold/Console/controller/controller.stub b/src/Scaffold/Console/controller/controller.stub deleted file mode 100644 index 6797a76fa..000000000 --- a/src/Scaffold/Console/controller/controller.stub +++ /dev/null @@ -1,25 +0,0 @@ - - - - -fatalError): ?> - - 'layout']) ?> - -
- formRender() ?> -
- -
-
- - - - or Cancel - -
-
- - - - - -

fatalError) ?>

-

Return to {{lower_title_name}} list

- - diff --git a/src/Scaffold/Console/controller/index.stub b/src/Scaffold/Console/controller/index.stub deleted file mode 100644 index 766877d92..000000000 --- a/src/Scaffold/Console/controller/index.stub +++ /dev/null @@ -1,2 +0,0 @@ - -listRender() ?> diff --git a/src/Scaffold/Console/controller/preview.stub b/src/Scaffold/Console/controller/preview.stub deleted file mode 100644 index df5524cd4..000000000 --- a/src/Scaffold/Console/controller/preview.stub +++ /dev/null @@ -1,19 +0,0 @@ - - - - -fatalError): ?> - -
- formRenderPreview() ?> -
- - - -

fatalError) ?>

-

Return to {{lower_title_name}} list

- - diff --git a/src/Scaffold/Console/controller/update.stub b/src/Scaffold/Console/controller/update.stub deleted file mode 100644 index 7812f2b74..000000000 --- a/src/Scaffold/Console/controller/update.stub +++ /dev/null @@ -1,56 +0,0 @@ - - - - -fatalError): ?> - - 'layout']) ?> - -
- formRender() ?> -
- -
-
- - - - - or Cancel - -
-
- - - - - -

fatalError) ?>

-

Return to {{lower_title_name}} list

- - diff --git a/src/Scaffold/Console/formwidget/formwidget.stub b/src/Scaffold/Console/formwidget/formwidget.stub deleted file mode 100644 index 9fcf5045b..000000000 --- a/src/Scaffold/Console/formwidget/formwidget.stub +++ /dev/null @@ -1,57 +0,0 @@ -prepareVars(); - return $this->makePartial('{{lower_name}}'); - } - - /** - * Prepares the form widget view data - */ - public function prepareVars() - { - $this->vars['name'] = $this->formField->getName(); - $this->vars['value'] = $this->getLoadValue(); - $this->vars['model'] = $this->model; - } - - /** - * @inheritDoc - */ - public function loadAssets() - { - $this->addCss('css/{{lower_name}}.css', '{{author}}.{{plugin}}'); - $this->addJs('js/{{lower_name}}.js', '{{author}}.{{plugin}}'); - } - - /** - * @inheritDoc - */ - public function getSaveValue($value) - { - return $value; - } -} diff --git a/src/Scaffold/Console/formwidget/javascript.stub b/src/Scaffold/Console/formwidget/javascript.stub deleted file mode 100644 index d4765f0b0..000000000 --- a/src/Scaffold/Console/formwidget/javascript.stub +++ /dev/null @@ -1,5 +0,0 @@ -/* - * This is a sample JavaScript file used by {{name}} - * - * You can delete this file if you want - */ diff --git a/src/Scaffold/Console/formwidget/partial.stub b/src/Scaffold/Console/formwidget/partial.stub deleted file mode 100644 index f311f175c..000000000 --- a/src/Scaffold/Console/formwidget/partial.stub +++ /dev/null @@ -1,17 +0,0 @@ -previewMode): ?> - -
- -
- - - - - - diff --git a/src/Scaffold/Console/formwidget/stylesheet.stub b/src/Scaffold/Console/formwidget/stylesheet.stub deleted file mode 100644 index 203c17aff..000000000 --- a/src/Scaffold/Console/formwidget/stylesheet.stub +++ /dev/null @@ -1,5 +0,0 @@ -/* - * This is a sample StyleSheet file used by {{name}} - * - * You can delete this file if you want - */ diff --git a/src/Scaffold/Console/model/columns.stub b/src/Scaffold/Console/model/columns.stub deleted file mode 100644 index b11160b42..000000000 --- a/src/Scaffold/Console/model/columns.stub +++ /dev/null @@ -1,8 +0,0 @@ -# =================================== -# List Column Definitions -# =================================== - -columns: - id: - label: ID - searchable: true diff --git a/src/Scaffold/Console/model/create_table.stub b/src/Scaffold/Console/model/create_table.stub deleted file mode 100644 index 761959ed3..000000000 --- a/src/Scaffold/Console/model/create_table.stub +++ /dev/null @@ -1,22 +0,0 @@ -engine = 'InnoDB'; - $table->increments('id'); - $table->timestamps(); - }); - } - - public function down() - { - Schema::dropIfExists('{{lower_author}}_{{lower_plugin}}_{{snake_plural_name}}'); - } -} diff --git a/src/Scaffold/Console/model/fields.stub b/src/Scaffold/Console/model/fields.stub deleted file mode 100644 index c611f31c7..000000000 --- a/src/Scaffold/Console/model/fields.stub +++ /dev/null @@ -1,8 +0,0 @@ -# =================================== -# Form Field Definitions -# =================================== - -fields: - id: - label: ID - disabled: true diff --git a/src/Scaffold/Console/model/model.stub b/src/Scaffold/Console/model/model.stub deleted file mode 100644 index 0816de62b..000000000 --- a/src/Scaffold/Console/model/model.stub +++ /dev/null @@ -1,74 +0,0 @@ - '{{name}}', - 'description' => 'No description provided yet...', - 'author' => '{{author}}', - 'icon' => 'icon-leaf' - ]; - } - - /** - * Register method, called when the plugin is first registered. - * - * @return void - */ - public function register() - { - - } - - /** - * Boot method, called right before the request route. - * - * @return array - */ - public function boot() - { - - } - - /** - * Registers any front-end components implemented in this plugin. - * - * @return array - */ - public function registerComponents() - { - return []; // Remove this line to activate - - return [ - '{{studly_author}}\{{studly_name}}\Components\MyComponent' => 'myComponent', - ]; - } - - /** - * Registers any back-end permissions used by this plugin. - * - * @return array - */ - public function registerPermissions() - { - return []; // Remove this line to activate - - return [ - '{{lower_author}}.{{lower_name}}.some_permission' => [ - 'tab' => '{{name}}', - 'label' => 'Some permission', - 'roles' => [UserRole::CODE_DEVELOPER, UserRole::CODE_PUBLISHER], - ], - ]; - } - - /** - * Registers back-end navigation items for this plugin. - * - * @return array - */ - public function registerNavigation() - { - return []; // Remove this line to activate - - return [ - '{{lower_name}}' => [ - 'label' => '{{name}}', - 'url' => Backend::url('{{lower_author}}/{{lower_name}}/mycontroller'), - 'icon' => 'icon-leaf', - 'permissions' => ['{{lower_author}}.{{lower_name}}.*'], - 'order' => 500, - ], - ]; - } -} diff --git a/src/Scaffold/Console/plugin/version.stub b/src/Scaffold/Console/plugin/version.stub deleted file mode 100644 index 496b830b1..000000000 --- a/src/Scaffold/Console/plugin/version.stub +++ /dev/null @@ -1 +0,0 @@ -1.0.1: First version of {{name}} diff --git a/src/Scaffold/Console/reportwidget/reportwidget.stub b/src/Scaffold/Console/reportwidget/reportwidget.stub deleted file mode 100644 index bfe197259..000000000 --- a/src/Scaffold/Console/reportwidget/reportwidget.stub +++ /dev/null @@ -1,63 +0,0 @@ - [ - 'title' => 'backend::lang.dashboard.widget_title_label', - 'default' => '{{title_name}} Report Widget', - 'type' => 'string', - 'validationPattern' => '^.+$', - 'validationMessage' => 'backend::lang.dashboard.widget_title_error', - ], - ]; - } - - /** - * Adds widget specific asset files. Use $this->addJs() and $this->addCss() - * to register new assets to include on the page. - * @return void - */ - protected function loadAssets() - { - } - - /** - * Renders the widget's primary contents. - * @return string HTML markup supplied by this widget. - */ - public function render() - { - try { - $this->prepareVars(); - } catch (Exception $ex) { - $this->vars['error'] = $ex->getMessage(); - } - - return $this->makePartial('{{lower_name}}'); - } - - /** - * Prepares the report widget view data - */ - public function prepareVars() - { - } -} diff --git a/src/Scaffold/Console/reportwidget/widget.stub b/src/Scaffold/Console/reportwidget/widget.stub deleted file mode 100644 index 13f9152e8..000000000 --- a/src/Scaffold/Console/reportwidget/widget.stub +++ /dev/null @@ -1,9 +0,0 @@ -
-

property('title')) ?>

- - -

This is the default partial content.

- -

- -
diff --git a/src/Scaffold/Console/settings/fields.stub b/src/Scaffold/Console/settings/fields.stub deleted file mode 100644 index 7a890bd71..000000000 --- a/src/Scaffold/Console/settings/fields.stub +++ /dev/null @@ -1,7 +0,0 @@ -# =================================== -# Form Field Definitions -# =================================== - -fields: - settings_option: - label: This is a sample settings field used by {{author}}.{{plugin}} diff --git a/src/Scaffold/Console/settings/model.stub b/src/Scaffold/Console/settings/model.stub deleted file mode 100644 index 740e775a9..000000000 --- a/src/Scaffold/Console/settings/model.stub +++ /dev/null @@ -1,31 +0,0 @@ - -

Page not found

-

We're sorry, but the page you requested cannot be found.

- \ No newline at end of file diff --git a/src/Scaffold/Console/theme/pages/error.stub b/src/Scaffold/Console/theme/pages/error.stub deleted file mode 100644 index 6767bc687..000000000 --- a/src/Scaffold/Console/theme/pages/error.stub +++ /dev/null @@ -1,8 +0,0 @@ -title = "Error page (500)" -url = "/error" -layout = "default" -== -
-

Error

-

We're sorry, but something went wrong and the page cannot be displayed.

-
\ No newline at end of file diff --git a/src/Scaffold/Console/theme/pages/home.stub b/src/Scaffold/Console/theme/pages/home.stub deleted file mode 100644 index ca87de8cb..000000000 --- a/src/Scaffold/Console/theme/pages/home.stub +++ /dev/null @@ -1,7 +0,0 @@ -title = "Home" -url = "/" -layout = "default" -== -
-

Home Page

-
\ No newline at end of file diff --git a/src/Scaffold/Console/theme/partials/meta/seo.stub b/src/Scaffold/Console/theme/partials/meta/seo.stub deleted file mode 100644 index 332bb2b08..000000000 --- a/src/Scaffold/Console/theme/partials/meta/seo.stub +++ /dev/null @@ -1,11 +0,0 @@ -{% if this.theme.googleanalytics_id is not empty %} - - - -{% endif %} diff --git a/src/Scaffold/Console/theme/partials/meta/styles.stub b/src/Scaffold/Console/theme/partials/meta/styles.stub deleted file mode 100644 index 8c4144b47..000000000 --- a/src/Scaffold/Console/theme/partials/meta/styles.stub +++ /dev/null @@ -1,4 +0,0 @@ - - -{% styles %} -{% placeholder head %} diff --git a/src/Scaffold/Console/theme/partials/site/footer.stub b/src/Scaffold/Console/theme/partials/site/footer.stub deleted file mode 100644 index 565e8bd4e..000000000 --- a/src/Scaffold/Console/theme/partials/site/footer.stub +++ /dev/null @@ -1,17 +0,0 @@ - - - {% scripts %} - - {% flash %} -

- {{ message }} -

- {% endflash %} - - \ No newline at end of file diff --git a/src/Scaffold/Console/theme/partials/site/header.stub b/src/Scaffold/Console/theme/partials/site/header.stub deleted file mode 100644 index cadd5efcf..000000000 --- a/src/Scaffold/Console/theme/partials/site/header.stub +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - {% placeholder page_title default %}{{ this.page.title }}{% endplaceholder %} - {% partial "meta/styles" %} - {% partial "meta/seo" %} - - - {% set pageId = this.page.id %} - {% set pageTitle = this.page.title %} - {% if pageId is empty %} - {% set pageId = page.id %} - {% endif %} - {% if pageTitle is empty %} - {% set pageTitle = page.title %} - {% endif %} - \ No newline at end of file diff --git a/src/Scaffold/Console/theme/theme.stub b/src/Scaffold/Console/theme/theme.stub deleted file mode 100644 index ef6ca860f..000000000 --- a/src/Scaffold/Console/theme/theme.stub +++ /dev/null @@ -1,9 +0,0 @@ -name: "{{code}}" -description: "No description provided yet..." -author: "Winter CMS Scaffold" -homepage: "https://example.com" -code: "{{code}}" -form: - fields: - googleanalytics_id: - label: 'Google Analytics ID' \ No newline at end of file diff --git a/src/Scaffold/Console/theme/version.stub b/src/Scaffold/Console/theme/version.stub deleted file mode 100644 index bd1f5e6b1..000000000 --- a/src/Scaffold/Console/theme/version.stub +++ /dev/null @@ -1 +0,0 @@ -1.0.1: 'Initial version' diff --git a/src/Scaffold/GeneratorCommand.php b/src/Scaffold/GeneratorCommand.php index b0af152c4..94dfc245a 100644 --- a/src/Scaffold/GeneratorCommand.php +++ b/src/Scaffold/GeneratorCommand.php @@ -1,41 +1,31 @@ getPluginInput(); + $plugin = $this->getPluginIdentifier(); $parts = explode('.', $plugin); $name = array_pop($parts); @@ -230,7 +220,7 @@ protected function getSourcePath() * * @return string */ - protected function getPluginInput() + protected function getPluginIdentifier() { return $this->argument('plugin'); } diff --git a/src/Scaffold/ScaffoldServiceProvider.php b/src/Scaffold/ScaffoldServiceProvider.php deleted file mode 100644 index 5d50a9cba..000000000 --- a/src/Scaffold/ScaffoldServiceProvider.php +++ /dev/null @@ -1,68 +0,0 @@ - \Winter\Storm\Scaffold\Console\CreateTheme::class, - 'command.create.plugin' => \Winter\Storm\Scaffold\Console\CreatePlugin::class, - 'command.create.model' => \Winter\Storm\Scaffold\Console\CreateModel::class, - 'command.create.settings' => \Winter\Storm\Scaffold\Console\CreateSettings::class, - 'command.create.controller' => \Winter\Storm\Scaffold\Console\CreateController::class, - 'command.create.component' => \Winter\Storm\Scaffold\Console\CreateComponent::class, - 'command.create.formwidget' => \Winter\Storm\Scaffold\Console\CreateFormWidget::class, - 'command.create.reportwidget' => \Winter\Storm\Scaffold\Console\CreateReportWidget::class, - 'command.create.command' => \Winter\Storm\Scaffold\Console\CreateCommand::class, - ]; - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - if ($this->app->runningInConsole()) { - $this->commands( - [ - 'command.create.theme', - 'command.create.plugin', - 'command.create.model', - 'command.create.settings', - 'command.create.controller', - 'command.create.component', - 'command.create.formwidget', - 'command.create.reportwidget', - 'command.create.command', - ] - ); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return [ - 'command.create.theme', - 'command.create.plugin', - 'command.create.model', - 'command.create.settings', - 'command.create.controller', - 'command.create.component', - 'command.create.formwidget', - 'command.create.reportwidget', - 'command.create.command', - ]; - } -} diff --git a/src/Support/Traits/Singleton.php b/src/Support/Traits/Singleton.php index 1da6e74f3..79d0bb6cd 100644 --- a/src/Support/Traits/Singleton.php +++ b/src/Support/Traits/Singleton.php @@ -14,6 +14,8 @@ trait Singleton /** * Create a new instance of this singleton. + * + * @return static */ final public static function instance() { diff --git a/src/Support/aliases.php b/src/Support/aliases.php index 74f1a0f7d..c29f443da 100644 --- a/src/Support/aliases.php +++ b/src/Support/aliases.php @@ -15,73 +15,66 @@ class_alias(\Winter\Storm\Argon\ArgonServiceProvider::class, \October\Rain\Argon /** * Alias October\Rain\Assetic */ -class_alias(\Winter\Storm\Assetic\Asset\AssetCache::class, \October\Rain\Assetic\Asset\AssetCache::class); -class_alias(\Winter\Storm\Assetic\Asset\AssetCollection::class, \October\Rain\Assetic\Asset\AssetCollection::class); -class_alias(\Winter\Storm\Assetic\Asset\AssetCollectionInterface::class, \October\Rain\Assetic\Asset\AssetCollectionInterface::class); -class_alias(\Winter\Storm\Assetic\Asset\AssetInterface::class, \October\Rain\Assetic\Asset\AssetInterface::class); -class_alias(\Winter\Storm\Assetic\Asset\AssetReference::class, \October\Rain\Assetic\Asset\AssetReference::class); -class_alias(\Winter\Storm\Assetic\Asset\BaseAsset::class, \October\Rain\Assetic\Asset\BaseAsset::class); -class_alias(\Winter\Storm\Assetic\Asset\FileAsset::class, \October\Rain\Assetic\Asset\FileAsset::class); -class_alias(\Winter\Storm\Assetic\Asset\GlobAsset::class, \October\Rain\Assetic\Asset\GlobAsset::class); -class_alias(\Winter\Storm\Assetic\Asset\HttpAsset::class, \October\Rain\Assetic\Asset\HttpAsset::class); -class_alias(\Winter\Storm\Assetic\Asset\Iterator\AssetCollectionFilterIterator::class, \October\Rain\Assetic\Asset\Iterator\AssetCollectionFilterIterator::class); -class_alias(\Winter\Storm\Assetic\Asset\Iterator\AssetCollectionIterator::class, \October\Rain\Assetic\Asset\Iterator\AssetCollectionIterator::class); -class_alias(\Winter\Storm\Assetic\Asset\StringAsset::class, \October\Rain\Assetic\Asset\StringAsset::class); -class_alias(\Winter\Storm\Assetic\AssetManager::class, \October\Rain\Assetic\AssetManager::class); -class_alias(\Winter\Storm\Assetic\AssetWriter::class, \October\Rain\Assetic\AssetWriter::class); -class_alias(\Winter\Storm\Assetic\Cache\ApcCache::class, \October\Rain\Assetic\Cache\ApcCache::class); -class_alias(\Winter\Storm\Assetic\Cache\ArrayCache::class, \October\Rain\Assetic\Cache\ArrayCache::class); -class_alias(\Winter\Storm\Assetic\Cache\CacheInterface::class, \October\Rain\Assetic\Cache\CacheInterface::class); -class_alias(\Winter\Storm\Assetic\Cache\ConfigCache::class, \October\Rain\Assetic\Cache\ConfigCache::class); -class_alias(\Winter\Storm\Assetic\Cache\ExpiringCache::class, \October\Rain\Assetic\Cache\ExpiringCache::class); -class_alias(\Winter\Storm\Assetic\Cache\FilesystemCache::class, \October\Rain\Assetic\Cache\FilesystemCache::class); -class_alias(\Winter\Storm\Assetic\Exception\Exception::class, \October\Rain\Assetic\Exception\Exception::class); -class_alias(\Winter\Storm\Assetic\Exception\FilterException::class, \October\Rain\Assetic\Exception\FilterException::class); -class_alias(\Winter\Storm\Assetic\Factory\AssetFactory::class, \October\Rain\Assetic\Factory\AssetFactory::class); -class_alias(\Winter\Storm\Assetic\Factory\LazyAssetManager::class, \October\Rain\Assetic\Factory\LazyAssetManager::class); -class_alias(\Winter\Storm\Assetic\Factory\Loader\BasePhpFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\BasePhpFormulaLoader::class); -class_alias(\Winter\Storm\Assetic\Factory\Loader\CachedFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\CachedFormulaLoader::class); -class_alias(\Winter\Storm\Assetic\Factory\Loader\FormulaLoaderInterface::class, \October\Rain\Assetic\Factory\Loader\FormulaLoaderInterface::class); -class_alias(\Winter\Storm\Assetic\Factory\Loader\FunctionCallsFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\FunctionCallsFormulaLoader::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\CoalescingDirectoryResource::class, \October\Rain\Assetic\Factory\Resource\CoalescingDirectoryResource::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\DirectoryResource::class, \October\Rain\Assetic\Factory\Resource\DirectoryResource::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\DirectoryResourceFilterIterator::class, \October\Rain\Assetic\Factory\Resource\DirectoryResourceFilterIterator::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\DirectoryResourceIterator::class, \October\Rain\Assetic\Factory\Resource\DirectoryResourceIterator::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\FileResource::class, \October\Rain\Assetic\Factory\Resource\FileResource::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\IteratorResourceInterface::class, \October\Rain\Assetic\Factory\Resource\IteratorResourceInterface::class); -class_alias(\Winter\Storm\Assetic\Factory\Resource\ResourceInterface::class, \October\Rain\Assetic\Factory\Resource\ResourceInterface::class); -class_alias(\Winter\Storm\Assetic\Factory\Worker\CacheBustingWorker::class, \October\Rain\Assetic\Factory\Worker\CacheBustingWorker::class); -class_alias(\Winter\Storm\Assetic\Factory\Worker\EnsureFilterWorker::class, \October\Rain\Assetic\Factory\Worker\EnsureFilterWorker::class); -class_alias(\Winter\Storm\Assetic\Factory\Worker\WorkerInterface::class, \October\Rain\Assetic\Factory\Worker\WorkerInterface::class); -class_alias(\Winter\Storm\Assetic\Filter\BaseCssFilter::class, \October\Rain\Assetic\Filter\BaseCssFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\CallablesFilter::class, \October\Rain\Assetic\Filter\CallablesFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\CssCacheBustingFilter::class, \October\Rain\Assetic\Filter\CssCacheBustingFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\CssImportFilter::class, \October\Rain\Assetic\Filter\CssImportFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\CssMinFilter::class, \October\Rain\Assetic\Filter\CssMinFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\CssRewriteFilter::class, \October\Rain\Assetic\Filter\CssRewriteFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\DependencyExtractorInterface::class, \October\Rain\Assetic\Filter\DependencyExtractorInterface::class); -class_alias(\Winter\Storm\Assetic\Filter\FilterCollection::class, \October\Rain\Assetic\Filter\FilterCollection::class); -class_alias(\Winter\Storm\Assetic\Filter\FilterInterface::class, \October\Rain\Assetic\Filter\FilterInterface::class); -class_alias(\Winter\Storm\Assetic\Filter\HashableInterface::class, \October\Rain\Assetic\Filter\HashableInterface::class); -class_alias(\Winter\Storm\Assetic\Filter\JavascriptImporter::class, \October\Rain\Assetic\Filter\JavascriptImporter::class); -class_alias(\Winter\Storm\Assetic\Filter\JSMinFilter::class, \October\Rain\Assetic\Filter\JSMinFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\JSMinPlusFilter::class, \October\Rain\Assetic\Filter\JSMinPlusFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\JSqueezeFilter::class, \October\Rain\Assetic\Filter\JSqueezeFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\LessCompiler::class, \October\Rain\Assetic\Filter\LessCompiler::class); -class_alias(\Winter\Storm\Assetic\Filter\LessphpFilter::class, \October\Rain\Assetic\Filter\LessphpFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\MinifyCssCompressorFilter::class, \October\Rain\Assetic\Filter\MinifyCssCompressorFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\PackagerFilter::class, \October\Rain\Assetic\Filter\PackagerFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\PackerFilter::class, \October\Rain\Assetic\Filter\PackerFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\ScssCompiler::class, \October\Rain\Assetic\Filter\ScssCompiler::class); -class_alias(\Winter\Storm\Assetic\Filter\ScssphpFilter::class, \October\Rain\Assetic\Filter\ScssphpFilter::class); -class_alias(\Winter\Storm\Assetic\Filter\StylesheetMinify::class, \October\Rain\Assetic\Filter\StylesheetMinify::class); -class_alias(\Winter\Storm\Assetic\FilterManager::class, \October\Rain\Assetic\FilterManager::class); -class_alias(\Winter\Storm\Assetic\Util\CssUtils::class, \October\Rain\Assetic\Util\CssUtils::class); -class_alias(\Winter\Storm\Assetic\Util\FilesystemUtils::class, \October\Rain\Assetic\Util\FilesystemUtils::class); -class_alias(\Winter\Storm\Assetic\Util\LessUtils::class, \October\Rain\Assetic\Util\LessUtils::class); -class_alias(\Winter\Storm\Assetic\Util\SassUtils::class, \October\Rain\Assetic\Util\SassUtils::class); -class_alias(\Winter\Storm\Assetic\Util\TraversableString::class, \October\Rain\Assetic\Util\TraversableString::class); -class_alias(\Winter\Storm\Assetic\Util\VarUtils::class, \October\Rain\Assetic\Util\VarUtils::class); +class_alias(\Assetic\Asset\AssetCache::class, \October\Rain\Assetic\Asset\AssetCache::class); +class_alias(\Assetic\Asset\AssetCollection::class, \October\Rain\Assetic\Asset\AssetCollection::class); +class_alias(\Assetic\Contracts\Asset\AssetCollectionInterface::class, \October\Rain\Assetic\Asset\AssetCollectionInterface::class); +class_alias(\Assetic\Contracts\Asset\AssetInterface::class, \October\Rain\Assetic\Asset\AssetInterface::class); +class_alias(\Assetic\Asset\AssetReference::class, \October\Rain\Assetic\Asset\AssetReference::class); +class_alias(\Assetic\Asset\BaseAsset::class, \October\Rain\Assetic\Asset\BaseAsset::class); +class_alias(\Assetic\Asset\FileAsset::class, \October\Rain\Assetic\Asset\FileAsset::class); +class_alias(\Assetic\Asset\GlobAsset::class, \October\Rain\Assetic\Asset\GlobAsset::class); +class_alias(\Assetic\Asset\HttpAsset::class, \October\Rain\Assetic\Asset\HttpAsset::class); +class_alias(\Assetic\Asset\Iterator\AssetCollectionFilterIterator::class, \October\Rain\Assetic\Asset\Iterator\AssetCollectionFilterIterator::class); +class_alias(\Assetic\Asset\Iterator\AssetCollectionIterator::class, \October\Rain\Assetic\Asset\Iterator\AssetCollectionIterator::class); +class_alias(\Assetic\Asset\StringAsset::class, \October\Rain\Assetic\Asset\StringAsset::class); +class_alias(\Assetic\AssetManager::class, \October\Rain\Assetic\AssetManager::class); +class_alias(\Assetic\AssetWriter::class, \October\Rain\Assetic\AssetWriter::class); +class_alias(\Assetic\Cache\ArrayCache::class, \October\Rain\Assetic\Cache\ArrayCache::class); +class_alias(\Assetic\Contracts\Cache\CacheInterface::class, \October\Rain\Assetic\Cache\CacheInterface::class); +class_alias(\Assetic\Cache\ConfigCache::class, \October\Rain\Assetic\Cache\ConfigCache::class); +class_alias(\Assetic\Cache\ExpiringCache::class, \October\Rain\Assetic\Cache\ExpiringCache::class); +class_alias(\Winter\Storm\Parse\Assetic\Cache\FilesystemCache::class, \October\Rain\Assetic\Cache\FilesystemCache::class); +class_alias(\Assetic\Contracts\Exception\Exception::class, \October\Rain\Assetic\Exception\Exception::class); +class_alias(\Assetic\Exception\FilterException::class, \October\Rain\Assetic\Exception\FilterException::class); +class_alias(\Assetic\Factory\AssetFactory::class, \October\Rain\Assetic\Factory\AssetFactory::class); +class_alias(\Assetic\Factory\LazyAssetManager::class, \October\Rain\Assetic\Factory\LazyAssetManager::class); +class_alias(\Assetic\Factory\Loader\BasePhpFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\BasePhpFormulaLoader::class); +class_alias(\Assetic\Factory\Loader\CachedFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\CachedFormulaLoader::class); +class_alias(\Assetic\Contracts\Factory\Loader\FormulaLoaderInterface::class, \October\Rain\Assetic\Factory\Loader\FormulaLoaderInterface::class); +class_alias(\Assetic\Factory\Loader\FunctionCallsFormulaLoader::class, \October\Rain\Assetic\Factory\Loader\FunctionCallsFormulaLoader::class); +class_alias(\Assetic\Factory\Resource\CoalescingDirectoryResource::class, \October\Rain\Assetic\Factory\Resource\CoalescingDirectoryResource::class); +class_alias(\Assetic\Factory\Resource\DirectoryResource::class, \October\Rain\Assetic\Factory\Resource\DirectoryResource::class); +class_alias(\Assetic\Factory\Resource\DirectoryResourceFilterIterator::class, \October\Rain\Assetic\Factory\Resource\DirectoryResourceFilterIterator::class); +class_alias(\Assetic\Factory\Resource\DirectoryResourceIterator::class, \October\Rain\Assetic\Factory\Resource\DirectoryResourceIterator::class); +class_alias(\Assetic\Factory\Resource\FileResource::class, \October\Rain\Assetic\Factory\Resource\FileResource::class); +class_alias(\Assetic\Contracts\Factory\Resource\IteratorResourceInterface::class, \October\Rain\Assetic\Factory\Resource\IteratorResourceInterface::class); +class_alias(\Assetic\Contracts\Factory\Resource\ResourceInterface::class, \October\Rain\Assetic\Factory\Resource\ResourceInterface::class); +class_alias(\Assetic\Factory\Worker\CacheBustingWorker::class, \October\Rain\Assetic\Factory\Worker\CacheBustingWorker::class); +class_alias(\Assetic\Factory\Worker\EnsureFilterWorker::class, \October\Rain\Assetic\Factory\Worker\EnsureFilterWorker::class); +class_alias(\Assetic\Contracts\Factory\Worker\WorkerInterface::class, \October\Rain\Assetic\Factory\Worker\WorkerInterface::class); +class_alias(\Assetic\Filter\BaseCssFilter::class, \October\Rain\Assetic\Filter\BaseCssFilter::class); +class_alias(\Assetic\Filter\CallablesFilter::class, \October\Rain\Assetic\Filter\CallablesFilter::class); +class_alias(\Assetic\Filter\CssCacheBustingFilter::class, \October\Rain\Assetic\Filter\CssCacheBustingFilter::class); +class_alias(\Assetic\Filter\CssImportFilter::class, \October\Rain\Assetic\Filter\CssImportFilter::class); +class_alias(\Assetic\Filter\CssRewriteFilter::class, \October\Rain\Assetic\Filter\CssRewriteFilter::class); +class_alias(\Assetic\Contracts\Filter\DependencyExtractorInterface::class, \October\Rain\Assetic\Filter\DependencyExtractorInterface::class); +class_alias(\Assetic\Filter\FilterCollection::class, \October\Rain\Assetic\Filter\FilterCollection::class); +class_alias(\Assetic\Contracts\Filter\FilterInterface::class, \October\Rain\Assetic\Filter\FilterInterface::class); +class_alias(\Assetic\Contracts\Filter\HashableInterface::class, \October\Rain\Assetic\Filter\HashableInterface::class); +class_alias(\Winter\Storm\Parse\Assetic\Filter\JavascriptImporter::class, \October\Rain\Assetic\Filter\JavascriptImporter::class); +class_alias(\Winter\Storm\Parse\Assetic\Filter\LessCompiler::class, \October\Rain\Assetic\Filter\LessCompiler::class); +class_alias(\Assetic\Filter\LessphpFilter::class, \October\Rain\Assetic\Filter\LessphpFilter::class); +class_alias(\Assetic\Filter\PackerFilter::class, \October\Rain\Assetic\Filter\PackerFilter::class); +class_alias(\Winter\Storm\Parse\Assetic\Filter\ScssCompiler::class, \October\Rain\Assetic\Filter\ScssCompiler::class); +class_alias(\Assetic\Filter\ScssphpFilter::class, \October\Rain\Assetic\Filter\ScssphpFilter::class); +class_alias(\Assetic\Filter\StylesheetMinifyFilter::class, \October\Rain\Assetic\Filter\StylesheetMinify::class); +class_alias(\Assetic\FilterManager::class, \October\Rain\Assetic\FilterManager::class); +class_alias(\Assetic\Util\CssUtils::class, \October\Rain\Assetic\Util\CssUtils::class); +class_alias(\Assetic\Util\FilesystemUtils::class, \October\Rain\Assetic\Util\FilesystemUtils::class); +class_alias(\Assetic\Util\LessUtils::class, \October\Rain\Assetic\Util\LessUtils::class); +class_alias(\Assetic\Util\SassUtils::class, \October\Rain\Assetic\Util\SassUtils::class); +class_alias(\Assetic\Util\TraversableString::class, \October\Rain\Assetic\Util\TraversableString::class); +class_alias(\Assetic\Util\VarUtils::class, \October\Rain\Assetic\Util\VarUtils::class); /** * Alias October\Rain\Auth @@ -338,16 +331,7 @@ class_alias(\Winter\Storm\Router\UrlGenerator::class, \October\Rain\Router\UrlGe /** * Alias October\Rain\Scaffold */ -class_alias(\Winter\Storm\Scaffold\Console\CreateCommand::class, \October\Rain\Scaffold\Console\CreateCommand::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateComponent::class, \October\Rain\Scaffold\Console\CreateComponent::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateController::class, \October\Rain\Scaffold\Console\CreateController::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateFormWidget::class, \October\Rain\Scaffold\Console\CreateFormWidget::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateModel::class, \October\Rain\Scaffold\Console\CreateModel::class); -class_alias(\Winter\Storm\Scaffold\Console\CreatePlugin::class, \October\Rain\Scaffold\Console\CreatePlugin::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateReportWidget::class, \October\Rain\Scaffold\Console\CreateReportWidget::class); -class_alias(\Winter\Storm\Scaffold\Console\CreateTheme::class, \October\Rain\Scaffold\Console\CreateTheme::class); class_alias(\Winter\Storm\Scaffold\GeneratorCommand::class, \October\Rain\Scaffold\GeneratorCommand::class); -class_alias(\Winter\Storm\Scaffold\ScaffoldServiceProvider::class, \October\Rain\Scaffold\ScaffoldServiceProvider::class); /** * Alias October\Rain\Support diff --git a/tests/Assetic/MockAsset.php b/tests/Assetic/MockAsset.php deleted file mode 100644 index e3c56e802..000000000 --- a/tests/Assetic/MockAsset.php +++ /dev/null @@ -1,86 +0,0 @@ -content = $content; - } - - public function ensureFilter(FilterInterface $filter) - { - } - - public function getFilters() - { - } - - public function clearFilters() - { - } - - public function load(FilterInterface $additionalFilter = null) - { - } - - public function dump(FilterInterface $additionalFilter = null) - { - } - - public function getContent() - { - return $this->content; - } - - public function setContent($content) - { - $this->content = $content; - } - - public function getSourceRoot() - { - } - - public function getSourcePath() - { - } - - public function getSourceDirectory() - { - } - - public function getTargetPath() - { - } - - public function setTargetPath($targetPath) - { - } - - public function getLastModified() - { - } - - public function getVars() - { - } - - public function setValues(array $values) - { - } - - public function getValues() - { - } -} diff --git a/tests/Assetic/StylesheetMinifyTest.php b/tests/Assetic/StylesheetMinifyTest.php deleted file mode 100644 index a5bd16eaa..000000000 --- a/tests/Assetic/StylesheetMinifyTest.php +++ /dev/null @@ -1,120 +0,0 @@ -filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testEmptyClassPreserve() - { - $input = <<filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testSpecialCommentPreservation() - { - $input = 'body {/*! Keep me */}'; - $output = 'body{/*! Keep me */}'; - - $mockAsset = new MockAsset($input); - $result = new StylesheetMinify(); - $result->filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testCommentRemoval() - { - $input = 'body{/* First comment */} /* Second comment */'; - $output = 'body{}'; - - $mockAsset = new MockAsset($input); - $result = new StylesheetMinify(); - $result->filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testCommentPreservationInVar() - { - $input = '--ring-inset: var(--empty, /*!*/ /*!*/);'; - $output = '--ring-inset:var(--empty,/*!*/ /*!*/);'; - - $mockAsset = new MockAsset($input); - $result = new StylesheetMinify(); - $result->filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testUnitPreservationInVar() - { - $input = '--offset-width: 0px'; - $output = '--offset-width:0'; - - $mockAsset = new MockAsset($input); - $result = new StylesheetMinify(); - $result->filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } - - public function testAttributeSelectorsWithLess() - { - $input = <<filterDump($mockAsset); - - $this->assertEquals($output, $mockAsset->getContent()); - } -} diff --git a/tests/Events/DispatcherTest.php b/tests/Events/DispatcherTest.php index c48005a42..2cf08f419 100644 --- a/tests/Events/DispatcherTest.php +++ b/tests/Events/DispatcherTest.php @@ -53,6 +53,32 @@ public function testTypedClosureListen() $this->assertTrue($magic_value); } + public function testClosureWithValueArgument() + { + $original = false; + + $dispatcher = new Dispatcher(); + $dispatcher->listen('test', function ($value) { + $value = true; + }); + $dispatcher->dispatch('test', [$original]); + + $this->assertFalse($original); + } + + public function testClosureWithReferenceArgument() + { + $original = false; + + $dispatcher = new Dispatcher(); + $dispatcher->listen('test', function (&$value) { + $value = true; + }); + $dispatcher->dispatch('test', [&$original]); + + $this->assertTrue($original); + } + public function testStringEventPriorities() { $magic_value = 0; diff --git a/tests/Halcyon/SectionParserTest.php b/tests/Halcyon/SectionParserTest.php index 3381dc368..869a8de4b 100644 --- a/tests/Halcyon/SectionParserTest.php +++ b/tests/Halcyon/SectionParserTest.php @@ -55,6 +55,23 @@ public function testParse() $this->assertArrayHasKey("index", $result["settings"]["section"]); $this->assertEquals("value", $result["settings"]["section"]["index"]); + // Test > 3 sections + // Test > 3 sections + $result = SectionParser::parse( + 'title = "test"' . PHP_EOL . + 'url = "/test"' . PHP_EOL . + '==' . PHP_EOL . + 'assertSame($result['markup'], 'Start of markup content' . PHP_EOL . '==' . PHP_EOL . 'random separator detected'); + // Test zero sections $result = SectionParser::parse(""); $this->assertCount(3, $result); @@ -108,7 +125,6 @@ public function testParse() public function testParseOffset() { - // Test three sections $content = <<parse(file_get_contents(dirname(__DIR__) . '/fixtures/yaml/symfony3.yaml')); $this->assertEquals([ + // Form config file 'form' => [ - 'fields' => [ - 'testField' => [ - 'type' => 'text', - 'label' => 'Test field', - ], - 'testSelect' => [ - 'type' => 'select', - 'label' => 'Do you rock the casbah?', - 'options' => [ - '0' => 'Nope', - '1' => 'ROCK THE CASBAH!', - '2' => 2, - ], - ], - 'testSelectTwo' => [ - 'type' => 'select', - 'label' => 'Which decade of songs did you like?', - 'options' => [ - '1960s', - '1970s', - '1980s', - '1990s', - '2000s', - '2010s', - '2020s', - ], - ], - 'testBoolean' => [ - 'type' => 'select', - 'label' => 'Is the sky blue?', - 'options' => [ - 'true' => true, - 'false' => false, - ], - ], + // field options array, unquoted keys & values + 'options' => [ + '0.1' => '0.1', + '0.2' => '0.2', + ], + + // field options array, unquoted keys + 'options2' => [ + '0.1' => '0.1', + '0.2' => '0.2', + ], + + // Aligned colons + 'options3' => [ + '0.1' => '0.1', + '0.2' => '0.2', ], ], - ], $yaml); + + // version.yaml file + 'updates' => [ + '1.0.1' => 'First version of Plugin', + '1.0.2' => [ + 'Create plugin tables', + 'create_plugin_table.php', + ], + '1.1' => [ + 'Add new component', + 'create_component_table.php', + ], + '1.1.1' => [ + 'Update column property', + 'update_column_property.php', + ], + ], + ], $yaml['numeric_keys_not_supported']); } } diff --git a/tests/fixtures/yaml/symfony3.yaml b/tests/fixtures/yaml/symfony3.yaml index a51719f6d..4ad4a0ebd 100644 --- a/tests/fixtures/yaml/symfony3.yaml +++ b/tests/fixtures/yaml/symfony3.yaml @@ -1,31 +1,95 @@ -# Test fixture to test a YAML file that was valid in Symfony/Yaml 3, but not v4. - -form: - "fields": - testField: - type: text - label: Test field - testSelect: - type: select - label: Do you rock the casbah? - options: - 0: Nope - 1: ROCK THE CASBAH! - 2: 2 - testSelectTwo: - type: select - label: "Which decade of songs did you like?" - options: - - 1960s - - 1970s - - "1980s" - - '1990s' - - 2000s - - 2010s - - 2020s - testBoolean: - type: select - label: Is the sky blue? - options: - true: true - false: false +## +## Numeric keys are not supported: +## +numeric_keys_not_supported: + # Form config file + form: + # field options array, unquoted keys & values + options: + 0.1: 0.1 + 0.2: 0.2 + + # field options array, unquoted keys + options2: + 0.1: '0.1' + 0.2: '0.2' + + # Aligned colons + options3 : + 0.1 : 0.1 + 0.2 : 0.2 + + # version.yaml file + updates: + 1.0.1: First version of Plugin + 1.0.2: + - 'Create plugin tables' + - create_plugin_table.php + 1.1: + - 'Add new component' + - create_component_table.php + 1.1.1: + - 'Update column property' + - update_column_property.php + + + +## +## Could not be parsed as it uses an unsupported built-in tag - FIXED IN VERSIONYAMLPARSER +## +# unsupported_build_tag: +# ## Version.yaml unquoted !!! usage +# 1.0.0: First version of Plugin +# 2.0.0: !!! Updated for Winter v1.2+ +# 3.0.0: +# - Multiple lines of changes +# - !!! Surprise! Some of them are important + + + +# ## +# ## Non-string keys are not supported -> WONTFIX +# ## +# non_string_keys: +# # Reserved types as field options array +# options4: +# null: 'None' +# true: True +# FALSE: 'FALSE' + + + +# ## +# ## Malformed inline YAML string -> WONTFIX +# ## +# malformed_inline_yaml_string: +# ## Colorpicker form widget availableColors option +# ## Documentation has correct example showing values need to be quoted, wontfix +# color: +# label: Custom color +# type: colorpicker +# availableColors: [#000000, #ffffff, #f2f2f2] + + + +# ## +# ## Duplicate Key -> WONTFIX +# ## +# duplicate_key: +# ## Unintentional duplicate keys in form configuration +# myfield: +# label: 'Label' +# comment: author.plugin::lang.fields.myfield +# span: right +# type: text +# comment: 'Untranslated' + + + +# ## +# ## The reserved indicator "@" cannot start a plain scalar -> WONTFIX +# ## +# reserved_indicator: +# ## Old usage of the "@" application path symbol, replaced with ~ in 2015 +# ## @see https://github.com/wintercms/winter/commit/9d649ebb1e72624361f8152f39a8e9c097701792 +# list: @/plugins/myauthor/myplugin/models/mymodel/columns.yaml