first commit
This commit is contained in:
18
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/LICENSE
vendored
Normal file
18
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/LICENSE
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Copyright (c) 2015 Matthias Mullie
|
||||
|
||||
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.
|
||||
52
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/README.md
vendored
Normal file
52
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/README.md
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
# Path converter
|
||||
|
||||
[](https://travis-ci.org/matthiasmullie/path-converter)
|
||||
[](https://codecov.io/github/matthiasmullie/path-converter)
|
||||
[](https://scrutinizer-ci.com/g/matthiasmullie/path-converter)
|
||||
[](https://packagist.org/packages/matthiasmullie/path-converter)
|
||||
[](https://packagist.org/packages/matthiasmullie/path-converter)
|
||||
[](https://github.com/matthiasmullie/path-converter/blob/master/LICENSE)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
use MatthiasMullie\PathConverter\Converter;
|
||||
|
||||
$from = '/css/imports/icons.css';
|
||||
$to = '/css/minified.css';
|
||||
|
||||
$converter = new Converter($from, $to);
|
||||
$result = $converter->convert('../../images/icon.jpg');
|
||||
// $result is now '../images/icon.jpg'
|
||||
```
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
### __construct($from, $to)
|
||||
|
||||
The object constructor accepts 2 paths: the source path your file(s) is/are
|
||||
currently relative to, and the target path to convert to.
|
||||
|
||||
### convert($path): string
|
||||
|
||||
$path is the relative file, which is currently relative to $from (in
|
||||
constructor). The return value will be the relative path of this same file, but
|
||||
now relative to $to (in constructor)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Simply add a dependency on matthiasmullie/path-converter to your composer.json file if you use [Composer](https://getcomposer.org/) to manage the dependencies of your project:
|
||||
|
||||
```sh
|
||||
composer require matthiasmullie/path-converter
|
||||
```
|
||||
|
||||
Although it's recommended to use Composer, you can actually include these files anyway you want.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
PathConverter is [MIT](http://opensource.org/licenses/MIT) licensed.
|
||||
5
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/makefile
vendored
Normal file
5
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/makefile
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
docs:
|
||||
wget http://apigen.org/apigen.phar
|
||||
chmod +x apigen.phar
|
||||
php apigen.phar generate --source=src --destination=docs --template-theme=bootstrap
|
||||
rm apigen.phar
|
||||
11
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/phpunit.xml.dist
vendored
Normal file
11
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit colors="true" bootstrap="tests/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Path converter test suite">
|
||||
<directory suffix="Test.php">tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
204
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/Converter.php
vendored
Normal file
204
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/Converter.php
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace MatthiasMullie\PathConverter;
|
||||
|
||||
/**
|
||||
* Convert paths relative from 1 file to another.
|
||||
*
|
||||
* E.g.
|
||||
* ../../images/icon.jpg relative to /css/imports/icons.css
|
||||
* becomes
|
||||
* ../images/icon.jpg relative to /css/minified.css
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/path-converter/issues
|
||||
*
|
||||
* @author Matthias Mullie <pathconverter@mullie.eu>
|
||||
* @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
class Converter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* @param string $from The original base path (directory, not file!)
|
||||
* @param string $to The new base path (directory, not file!)
|
||||
* @param string $root Root directory (defaults to `getcwd`)
|
||||
*/
|
||||
public function __construct($from, $to, $root = '')
|
||||
{
|
||||
$shared = $this->shared($from, $to);
|
||||
if ($shared === '') {
|
||||
// when both paths have nothing in common, one of them is probably
|
||||
// absolute while the other is relative
|
||||
$root = $root ?: getcwd();
|
||||
$from = strpos($from, $root) === 0 ? $from : preg_replace('/\/+/', '/', $root.'/'.$from);
|
||||
$to = strpos($to, $root) === 0 ? $to : preg_replace('/\/+/', '/', $root.'/'.$to);
|
||||
|
||||
// or traveling the tree via `..`
|
||||
// attempt to resolve path, or assume it's fine if it doesn't exist
|
||||
$from = @realpath($from) ?: $from;
|
||||
$to = @realpath($to) ?: $to;
|
||||
}
|
||||
|
||||
$from = $this->dirname($from);
|
||||
$to = $this->dirname($to);
|
||||
|
||||
$from = $this->normalize($from);
|
||||
$to = $this->normalize($to);
|
||||
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function normalize($path)
|
||||
{
|
||||
// deal with different operating systems' directory structure
|
||||
$path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');
|
||||
|
||||
// remove leading current directory.
|
||||
if (substr($path, 0, 2) === './') {
|
||||
$path = substr($path, 2);
|
||||
}
|
||||
|
||||
// remove references to current directory in the path.
|
||||
$path = str_replace('/./', '/', $path);
|
||||
|
||||
/*
|
||||
* Example:
|
||||
* /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif
|
||||
* to
|
||||
* /home/forkcms/frontend/core/layout/images/img.gif
|
||||
*/
|
||||
do {
|
||||
$path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
|
||||
} while ($count);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out the shared path of 2 locations.
|
||||
*
|
||||
* Example:
|
||||
* /home/forkcms/frontend/core/layout/images/img.gif
|
||||
* and
|
||||
* /home/forkcms/frontend/cache/minified_css
|
||||
* share
|
||||
* /home/forkcms/frontend
|
||||
*
|
||||
* @param string $path1
|
||||
* @param string $path2
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function shared($path1, $path2)
|
||||
{
|
||||
// $path could theoretically be empty (e.g. no path is given), in which
|
||||
// case it shouldn't expand to array(''), which would compare to one's
|
||||
// root /
|
||||
$path1 = $path1 ? explode('/', $path1) : array();
|
||||
$path2 = $path2 ? explode('/', $path2) : array();
|
||||
|
||||
$shared = array();
|
||||
|
||||
// compare paths & strip identical ancestors
|
||||
foreach ($path1 as $i => $chunk) {
|
||||
if (isset($path2[$i]) && $path1[$i] == $path2[$i]) {
|
||||
$shared[] = $chunk;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('/', $shared);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert paths relative from 1 file to another.
|
||||
*
|
||||
* E.g.
|
||||
* ../images/img.gif relative to /home/forkcms/frontend/core/layout/css
|
||||
* should become:
|
||||
* ../../core/layout/images/img.gif relative to
|
||||
* /home/forkcms/frontend/cache/minified_css
|
||||
*
|
||||
* @param string $path The relative path that needs to be converted
|
||||
*
|
||||
* @return string The new relative path
|
||||
*/
|
||||
public function convert($path)
|
||||
{
|
||||
// quit early if conversion makes no sense
|
||||
if ($this->from === $this->to) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$path = $this->normalize($path);
|
||||
// if we're not dealing with a relative path, just return absolute
|
||||
if (strpos($path, '/') === 0) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
// normalize paths
|
||||
$path = $this->normalize($this->from.'/'.$path);
|
||||
|
||||
// strip shared ancestor paths
|
||||
$shared = $this->shared($path, $this->to);
|
||||
$path = mb_substr($path, mb_strlen($shared));
|
||||
$to = mb_substr($this->to, mb_strlen($shared));
|
||||
|
||||
// add .. for every directory that needs to be traversed to new path
|
||||
$to = str_repeat('../', count(array_filter(explode('/', $to))));
|
||||
|
||||
return $to.ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the directory name from a path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function dirname($path)
|
||||
{
|
||||
if (@is_file($path)) {
|
||||
return dirname($path);
|
||||
}
|
||||
|
||||
if (@is_dir($path)) {
|
||||
return rtrim($path, '/');
|
||||
}
|
||||
|
||||
// no known file/dir, start making assumptions
|
||||
|
||||
// ends in / = dir
|
||||
if (mb_substr($path, -1) === '/') {
|
||||
return rtrim($path, '/');
|
||||
}
|
||||
|
||||
// has a dot in the name, likely a file
|
||||
if (preg_match('/.*\..*$/', basename($path)) !== 0) {
|
||||
return dirname($path);
|
||||
}
|
||||
|
||||
// you're on your own here!
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
24
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/ConverterInterface.php
vendored
Normal file
24
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/ConverterInterface.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace MatthiasMullie\PathConverter;
|
||||
|
||||
/**
|
||||
* Convert file paths.
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/path-converter/issues
|
||||
*
|
||||
* @author Matthias Mullie <pathconverter@mullie.eu>
|
||||
* @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
interface ConverterInterface
|
||||
{
|
||||
/**
|
||||
* Convert file paths.
|
||||
*
|
||||
* @param string $path The path to be converted
|
||||
*
|
||||
* @return string The new path
|
||||
*/
|
||||
public function convert($path);
|
||||
}
|
||||
23
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/NoConverter.php
vendored
Normal file
23
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/src/NoConverter.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace MatthiasMullie\PathConverter;
|
||||
|
||||
/**
|
||||
* Don't convert paths.
|
||||
*
|
||||
* Please report bugs on https://github.com/matthiasmullie/path-converter/issues
|
||||
*
|
||||
* @author Matthias Mullie <pathconverter@mullie.eu>
|
||||
* @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved
|
||||
* @license MIT License
|
||||
*/
|
||||
class NoConverter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function convert($path)
|
||||
{
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
125
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/ConverterTest.php
vendored
Normal file
125
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/ConverterTest.php
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace MatthiasMullie\PathConverter\Tests;
|
||||
|
||||
use MatthiasMullie\PathConverter\Converter;
|
||||
|
||||
/**
|
||||
* Converter test case.
|
||||
*/
|
||||
class ConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test Converter, provided by dataProvider.
|
||||
*
|
||||
* @test
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function convert($relative, $from, $to, $expected)
|
||||
{
|
||||
$converter = new Converter($from, $to);
|
||||
$result = $converter->convert($relative);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array [relative, from, to, expected result]
|
||||
*/
|
||||
public function dataProvider()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'/home/forkcms/frontend/core/layout/css',
|
||||
'/home/forkcms/frontend/cache/minified_css',
|
||||
'../../core/layout/images/img.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'../../images/icon.gif',
|
||||
'/css/imports/',
|
||||
'/css/',
|
||||
'../images/icon.gif',
|
||||
);
|
||||
|
||||
// absolute path - doesn't make sense :)
|
||||
$tests[] = array(
|
||||
'/home/username/file.txt',
|
||||
'/css/imports',
|
||||
'/css',
|
||||
'/home/username/file.txt',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'tests/css/sample/convert_relative_path/source',
|
||||
'tests/css/sample/convert_relative_path/source',
|
||||
'image.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'C:/My Documents/forkcms/frontend/core/layout/css',
|
||||
'C:/My Documents/forkcms/frontend/cache/minified_css',
|
||||
'../../core/layout/images/img.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/forkcms/forkcms/issues/1186
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'/Users/mathias/Documents/— Projecten/PROJECT_NAAM/Web/src/Backend/Core/Layout/Css/',
|
||||
'/Users/mathias/Documents/— Projecten/PROJECT_NAAM/Web/src/Backend/Cache/MinifiedCss/',
|
||||
'../../Core/Layout/images/img.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/path-converter/issues/1
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'/var/www/mysite.com/assets/some_random_folder_name/',
|
||||
'/var/www/mysite.com/assets/some_other_random_folder_name/',
|
||||
'../some_random_folder_name/image.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'/var/www/',
|
||||
'/',
|
||||
'var/www/image.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'/',
|
||||
'/var/www/',
|
||||
'../../image.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/path-converter/issues/4
|
||||
$tests[] = array(
|
||||
'rotissanser-webfont.eot',
|
||||
'typo3temp/assets/compressed/../../../typo3conf/ext/user_merkl/Resources/Public/Fonts/webfontkit-rotissanser/stylesheet.css',
|
||||
'typo3temp/assets/compressed/merged-abce7d875ee92a78bd5e1871ef774fbe.css',
|
||||
'../../../typo3conf/ext/user_merkl/Resources/Public/Fonts/webfontkit-rotissanser/rotissanser-webfont.eot',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/path-converter/issues/6
|
||||
$tests[] = array(
|
||||
'./../images/header-section/HeroImage.jpg',
|
||||
'/wordpress/wp-content/themes/racine/styles/',
|
||||
'/wordpress/wp-content/cache/min/',
|
||||
'../../themes/racine/images/header-section/HeroImage.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/path-converter/issues/6
|
||||
$tests[] = array(
|
||||
'../images/./header-section/HeroImage2.jpg',
|
||||
'/wordpress/wp-content/themes/racine/styles/',
|
||||
'/wordpress/wp-content/cache/min/',
|
||||
'../../themes/racine/images/header-section/HeroImage2.jpg',
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
||||
73
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/NoConverterTest.php
vendored
Normal file
73
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/NoConverterTest.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace MatthiasMullie\PathConverter\Tests;
|
||||
|
||||
use MatthiasMullie\PathConverter\NoConverter;
|
||||
|
||||
/**
|
||||
* Converter test case.
|
||||
*/
|
||||
class NoConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test Converter, provided by dataProvider.
|
||||
*
|
||||
* @test
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function convert($relative, $expected)
|
||||
{
|
||||
$converter = new NoConverter();
|
||||
$result = $converter->convert($relative);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array [relative, from, to, expected result]
|
||||
*/
|
||||
public function dataProvider()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'../images/img.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'../../images/icon.gif',
|
||||
'../../images/icon.gif',
|
||||
);
|
||||
|
||||
// absolute path - doesn't make sense :)
|
||||
$tests[] = array(
|
||||
'/home/username/file.txt',
|
||||
'/home/username/file.txt',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'image.jpg',
|
||||
);
|
||||
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'../images/img.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/forkcms/forkcms/issues/1186
|
||||
$tests[] = array(
|
||||
'../images/img.jpg',
|
||||
'../images/img.jpg',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/path-converter/issues/1
|
||||
$tests[] = array(
|
||||
'image.jpg',
|
||||
'image.jpg',
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
||||
3
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/bootstrap.php
vendored
Normal file
3
wp-content/plugins/wp-optimize/vendor/matthiasmullie/path-converter/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
Reference in New Issue
Block a user