summaryrefslogtreecommitdiffstats
path: root/vendor/riimu/kit-pathjoin
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/riimu/kit-pathjoin')
-rw-r--r--vendor/riimu/kit-pathjoin/CHANGES.md15
-rw-r--r--vendor/riimu/kit-pathjoin/LICENSE18
-rw-r--r--vendor/riimu/kit-pathjoin/README.md136
-rw-r--r--vendor/riimu/kit-pathjoin/composer.json23
-rw-r--r--vendor/riimu/kit-pathjoin/examples/example.php34
-rw-r--r--vendor/riimu/kit-pathjoin/src/Path.php175
-rw-r--r--vendor/riimu/kit-pathjoin/src/autoload.php12
7 files changed, 413 insertions, 0 deletions
diff --git a/vendor/riimu/kit-pathjoin/CHANGES.md b/vendor/riimu/kit-pathjoin/CHANGES.md
new file mode 100644
index 000000000..013618ad1
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/CHANGES.md
@@ -0,0 +1,15 @@
+# Changelog #
+
+## v1.1.1 (2015-08-09) ##
+
+ * Maintenance release that simply addresses some coding standards issues
+
+## v1.1.0 (2015-03-25) ##
+
+ * Added `Path::normalize()` method for normalizing a single path.
+ * The `Path::join()` method now correctly returns '.' instead of an empty
+ path, similar to the `dirname()` function.
+
+## v1.0.1 (2015-01-24) ##
+
+ * Improvements in code quality and documentation
diff --git a/vendor/riimu/kit-pathjoin/LICENSE b/vendor/riimu/kit-pathjoin/LICENSE
new file mode 100644
index 000000000..e48de6af8
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2014 - 2015 Riikka Kalliomäki
+
+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. \ No newline at end of file
diff --git a/vendor/riimu/kit-pathjoin/README.md b/vendor/riimu/kit-pathjoin/README.md
new file mode 100644
index 000000000..1b436bc90
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/README.md
@@ -0,0 +1,136 @@
+# Path joiner and normalizer #
+
+*PathJoin* is PHP library for normalizing and joining file system paths. The
+purpose of this library is to make easier to work with file system paths
+irregardless of the platform and the system directory separator.
+
+The purpose of file path normalization is to provide a single consistent file
+path representation. In other words, the normalization in this library will
+resolve `.` and `..` directory references and also condense multiple directory
+separators into one. This makes it much easier to avoid common problems when
+comparing paths against each other.
+
+While PHP provides a built in function `realpath()`, it is not usable in every
+case since it works by using the file system. This library simply combines and
+normalizes the paths using string handling. There is no requirement for the
+files or directories to be readable or even exist.
+
+The API documentation, which can be generated using Apigen, can be read online
+at: http://kit.riimu.net/api/pathjoin/
+
+[![Build Status](https://img.shields.io/travis/Riimu/Kit-PathJoin.svg?style=flat)](https://travis-ci.org/Riimu/Kit-PathJoin)
+[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PathJoin.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)
+[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Riimu/Kit-PathJoin.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)
+
+## Requirements ##
+
+In order to use this library, the following requirements must be met:
+
+ * PHP version 5.4
+
+## Installation ##
+
+This library can be installed by using [Composer](http://getcomposer.org/). In
+order to do this, you must download the latest Composer version and run the
+`require` command to add this library as a dependency to your project. The
+easiest way to complete these two tasks is to run the following two commands
+in your terminal:
+
+```
+php -r "readfile('https://getcomposer.org/installer');" | php
+php composer.phar require "riimu/kit-pathjoin:1.*"
+```
+
+If you already have Composer installed on your system and you know how to use
+it, you can also install this library by adding it as a dependency to your
+`composer.json` file and running the `composer install` command. Here is an
+example of what your `composer.json` file could look like:
+
+```json
+{
+ "require": {
+ "riimu/kit-pathjoin": "1.*"
+ }
+}
+```
+
+After installing this library via Composer, you can load the library by
+including the `vendor/autoload.php` file that was generated by Composer during
+the installation.
+
+### Manual installation ###
+
+You can also install this library manually without using Composer. In order to
+do this, you must download the [latest release](https://github.com/Riimu/Kit-PHPEncoder/releases/latest)
+and extract the `src` folder from the archive to your project folder. To load
+the library, you can simply include the `src/autoload.php` file that was
+provided in the archive.
+
+## Usage ##
+
+This library provides two convenient methods, `Path::normalize()` and
+`Path::join()`. Both of these methods work in a very similar fashion. The main
+difference is that while the `join()` method can accept multiple paths to join,
+the `normalize()` will only accept a single path. Both of the methods will
+return a normalized path as the result.
+
+The following example will contain numerous different use cases of the library:
+
+```php
+<?php
+
+require 'vendor/autoload.php';
+use Riimu\Kit\PathJoin\Path;
+
+// Both of the following will output 'foo/bar' on Unix and 'foo\bar' on Windows
+echo Path::normalize('foo/bar') . PHP_EOL;
+echo Path::join('foo', 'bar') . PHP_EOL;
+
+// The join method accepts multiple arguments or a single array
+echo Path::join('foo', 'bar', 'baz') . PHP_EOL; // outputs 'foo/bar/baz'
+echo Path::join(['foo', 'bar', 'baz']) . PHP_EOL; // outputs 'foo/bar/baz'
+
+// The '.' and '..' directory references will be resolved in the paths
+echo Path::normalize('foo/./bar/../baz') . PHP_EOL; // outputs 'foo/baz'
+echo Path::join(['foo/./', 'bar', '../baz']) . PHP_EOL; // outputs 'foo/baz'
+
+// Only the first path can denote an absolute path in the join method
+echo Path::join('/foo', '/bar/baz') . PHP_EOL; // outputs '/foo/bar/baz'
+echo Path::join('foo', '/bar') . PHP_EOL; // outputs 'foo/bar'
+echo Path::join('foo', '../bar', 'baz') . PHP_EOL; // outputs 'bar/baz'
+echo Path::join('', '/bar', 'baz') . PHP_EOL; // outputs 'bar/baz'
+
+// Relative paths can start with a '..', but absolute paths cannot
+echo Path::join('/foo', '../../bar', 'baz') . PHP_EOL; // outputs '/bar/baz'
+echo Path::join('foo', '../../bar', 'baz') . PHP_EOL; // outputs '../bar/baz'
+
+// Empty paths will result in a '.'
+echo Path::normalize('foo/..') . PHP_EOL;
+echo Path::join('foo', 'bar', '../..') . PHP_EOL;
+```
+
+The `Path::normalize()` also accepts a second parameter `$prependDrive` that
+takes a boolean value and defaults to true. On Windows platforms, the drive
+letter is important part of the absolute path. Thus, when the parameter is set
+to true, the method will prepend the drive letter of the current working
+directory to absolute paths if the absolute path does not provide one itself.
+
+The following example is true for Windows systems, if the working directory is
+located on the C: drive:
+
+```php
+<?php
+
+require 'vendor/autoload.php';
+use Riimu\Kit\PathJoin\Path;
+
+echo Path::normalize('/foo/bar') . PHP_EOL; // outputs 'C:\foo\Bar'
+echo Path::normalize('D:/foo/bar') . PHP_EOL; // outputs 'D:\foo\Bar'
+echo Path::normalize('/foo/bar', false) . PHP_EOL; // outputs '\foo\Bar'
+```
+
+## Credits ##
+
+This library is copyright 2014 - 2015 to Riikka Kalliomäki.
+
+See LICENSE for license and copying information.
diff --git a/vendor/riimu/kit-pathjoin/composer.json b/vendor/riimu/kit-pathjoin/composer.json
new file mode 100644
index 000000000..96d6dc21f
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "riimu/kit-pathjoin",
+ "type": "library",
+ "description": "Cross-platform library for normalizing and joining file system paths",
+ "homepage": "http://kit.riimu.net",
+ "keywords": ["normalize", "join", "file", "system", "path"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Riikka Kalliomäki",
+ "email": "riikka.kalliomaki@gmail.com",
+ "homepage": "http://riimu.net"
+ }
+ ],
+ "require": {
+ "php": ">=5.4.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Riimu\\Kit\\PathJoin\\": "src/"
+ }
+ }
+}
diff --git a/vendor/riimu/kit-pathjoin/examples/example.php b/vendor/riimu/kit-pathjoin/examples/example.php
new file mode 100644
index 000000000..81d64a025
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/examples/example.php
@@ -0,0 +1,34 @@
+<?php
+
+require '../src/autoload.php';
+use Riimu\Kit\PathJoin\Path;
+
+// Both of the following will output 'foo/bar' on Unix and 'foo\bar' on Windows
+echo Path::normalize('foo/bar') . PHP_EOL;
+echo Path::join('foo', 'bar') . PHP_EOL;
+
+// The join method accepts multiple arguments or a single array
+echo Path::join('foo', 'bar', 'baz') . PHP_EOL; // outputs 'foo/bar/baz'
+echo Path::join(['foo', 'bar', 'baz']) . PHP_EOL; // outputs 'foo/bar/baz'
+
+// The '.' and '..' directory references will be resolved in the paths
+echo Path::normalize('foo/./bar/../baz') . PHP_EOL; // outputs 'foo/baz'
+echo Path::join(['foo/./', 'bar', '../baz']) . PHP_EOL; // outputs 'foo/baz'
+
+// Only the first path can denote an absolute path in the join method
+echo Path::join('/foo', '/bar/baz') . PHP_EOL; // outputs '/foo/bar/baz'
+echo Path::join('foo', '/bar') . PHP_EOL; // outputs 'foo/bar'
+echo Path::join('foo', '../bar', 'baz') . PHP_EOL; // outputs 'bar/baz'
+echo Path::join('', '/bar', 'baz') . PHP_EOL; // outputs 'bar/baz'
+
+// Relative paths can start with a '..', but absolute paths cannot
+echo Path::join('/foo', '../../bar', 'baz') . PHP_EOL; // outputs '/bar/baz'
+echo Path::join('foo', '../../bar', 'baz') . PHP_EOL; // outputs '../bar/baz'
+
+// Empty path will result in a '.'
+echo Path::normalize('foo/..') . PHP_EOL;
+echo Path::join('foo', 'bar', '../..') . PHP_EOL;
+
+echo Path::normalize('/foo/bar') . PHP_EOL; // outputs 'C:\foo\Bar'
+echo Path::normalize('D:/foo/bar') . PHP_EOL; // outputs 'D:\foo\Bar'
+echo Path::normalize('/foo/bar', false) . PHP_EOL; // outputs '\foo\Bar'
diff --git a/vendor/riimu/kit-pathjoin/src/Path.php b/vendor/riimu/kit-pathjoin/src/Path.php
new file mode 100644
index 000000000..df62e7d22
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/src/Path.php
@@ -0,0 +1,175 @@
+<?php
+
+namespace Riimu\Kit\PathJoin;
+
+/**
+ * Cross-platform library for normalizing and joining file system paths.
+ * @author Riikka Kalliomäki <riikka.kalliomaki@gmail.com>
+ * @copyright Copyright (c) 2014, Riikka Kalliomäki
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ */
+class Path
+{
+ /**
+ * Normalizes the provided file system path.
+ *
+ * Normalizing file system paths means that all forward and backward
+ * slashes in the path will be replaced with the system directory separator
+ * and multiple directory separators will be condensed into one.
+ * Additionally, all `.` and `..` directory references will be resolved in
+ * the returned path.
+ *
+ * Note that if the normalized path is not an absolute path, the resulting
+ * path may begin with `..` directory references if it is not possible to
+ * resolve them simply by using string handling. You should also note that
+ * if the resulting path would result in an empty string, this method will
+ * return `.` instead.
+ *
+ * If the `$prependDrive` option is enabled, the normalized path will be
+ * prepended with the drive name on Windows platforms using the current
+ * working directory, if the path is an absolute path that does not include
+ * a drive name.
+ *
+ * @param string $path File system path to normalize
+ * @param bool $prependDrive True to prepend drive name to absolute paths
+ * @return string The normalizes file system path
+ */
+ public static function normalize($path, $prependDrive = true)
+ {
+ $path = self::join((string) $path);
+
+ if ($path[0] === DIRECTORY_SEPARATOR && $prependDrive) {
+ return strstr(getcwd(), DIRECTORY_SEPARATOR, true) . $path;
+ }
+
+ return $path;
+ }
+
+ /**
+ * Joins the provided file systems paths together and normalizes the result.
+ *
+ * The paths can be provided either as multiple arguments to this method
+ * or as an array. The paths will be joined using the system directory
+ * separator and the result will be normalized similar to the normalization
+ * method (the drive letter will not be prepended however).
+ *
+ * Note that unless the first path in the list is an absolute path, the
+ * entire resulting path will be treated as a relative path.
+ *
+ * @param string[]|string $paths File system paths to join
+ * @return string The joined file system paths
+ */
+ public static function join($paths)
+ {
+ $paths = self::getPaths(func_get_args());
+ $parts = self::getParts($paths);
+
+ $absolute = self::isAbsolute($paths[0]);
+ $root = $absolute ? array_shift($parts) . DIRECTORY_SEPARATOR : '';
+ $parts = self::resolve($parts, $absolute);
+
+ if ($parts === []) {
+ return $root ?: '.';
+ }
+
+ return $root . implode(DIRECTORY_SEPARATOR, $parts);
+ }
+
+ /**
+ * Returns the paths from the arguments list.
+ * @param array $args The arguments list
+ * @return string[] Paths from the arguments list
+ * @throws \InvalidArgumentException If the path array is empty
+ */
+ private static function getPaths($args)
+ {
+ if (is_array($args[0])) {
+ $args = $args[0];
+
+ if ($args === []) {
+ throw new \InvalidArgumentException('You must provide at least one path');
+ }
+ }
+
+ return $args;
+ }
+
+ /**
+ * Merges the paths and returns the individual parts.
+ * @param string[] $paths Array of paths
+ * @return string[] Parts in the paths merged into a single array
+ */
+ private static function getParts(array $paths)
+ {
+ return array_map('trim', explode('/', str_replace('\\', '/', implode('/', $paths))));
+ }
+
+ /**
+ * Tells if the path is an absolute path.
+ * @param string $path The file system path to test
+ * @return bool True if the path is an absolute path, false if not
+ */
+ private static function isAbsolute($path)
+ {
+ $path = trim($path);
+
+ if ($path === '') {
+ return false;
+ }
+
+ $length = strcspn($path, '/\\');
+
+ return $length === 0 || $path[$length - 1] === ':';
+ }
+
+ /**
+ * Resolves parent directory references and removes redundant entries.
+ * @param string[] $parts List of parts in the the path
+ * @param bool $absolute Whether the path is an absolute path or not
+ * @return string[] Resolved list of parts in the path
+ */
+ private static function resolve(array $parts, $absolute)
+ {
+ $resolved = [];
+
+ foreach ($parts as $path) {
+ if ($path === '..') {
+ self::resolveParent($resolved, $absolute);
+ } elseif (self::isValidPath($path)) {
+ $resolved[] = $path;
+ }
+ }
+
+ return $resolved;
+ }
+
+ /**
+ * Tells if the part of the path is valid and not empty.
+ * @param string $path Part of the path to check for redundancy
+ * @return bool True if the path is valid and not empty, false if not
+ * @throws \InvalidArgumentException If the path contains invalid characters
+ */
+ private static function isValidPath($path)
+ {
+ if (strpos($path, ':') !== false) {
+ throw new \InvalidArgumentException('Invalid path character ":"');
+ }
+
+ return $path !== '' && $path !== '.';
+ }
+
+ /**
+ * Resolves the relative parent directory for the path.
+ * @param string[] $parts Path parts to modify
+ * @param bool $absolute True if dealing with absolute path, false if not
+ * @return string|null The removed parent or null if nothing was removed
+ */
+ private static function resolveParent(& $parts, $absolute)
+ {
+ if ($absolute || !in_array(end($parts), ['..', false], true)) {
+ return array_pop($parts);
+ }
+
+ $parts[] = '..';
+ }
+}
diff --git a/vendor/riimu/kit-pathjoin/src/autoload.php b/vendor/riimu/kit-pathjoin/src/autoload.php
new file mode 100644
index 000000000..bc8572d6d
--- /dev/null
+++ b/vendor/riimu/kit-pathjoin/src/autoload.php
@@ -0,0 +1,12 @@
+<?php
+
+// Autoloader for loading the library when composer is not available
+spl_autoload_register(function ($class) {
+ if (strncmp($class, $ns = 'Riimu\\Kit\\PathJoin\\', strlen($ns)) === 0) {
+ $file = substr_replace($class, '\\', 0, strlen($ns)) . '.php';
+ $path = __DIR__ . str_replace('\\', DIRECTORY_SEPARATOR, $file);
+ if (file_exists($path)) {
+ require $path;
+ }
+ }
+});