First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
1
vendor/dnoegel/php-xdg-base-dir/.gitignore
vendored
Normal file
1
vendor/dnoegel/php-xdg-base-dir/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/vendor/
|
19
vendor/dnoegel/php-xdg-base-dir/LICENSE
vendored
Normal file
19
vendor/dnoegel/php-xdg-base-dir/LICENSE
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2014 Daniel Nögel
|
||||
|
||||
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.
|
38
vendor/dnoegel/php-xdg-base-dir/README.md
vendored
Normal file
38
vendor/dnoegel/php-xdg-base-dir/README.md
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
# XDG Base Directory
|
||||
|
||||
[](LICENSE.md)
|
||||
|
||||
Implementation of XDG Base Directory specification for php
|
||||
|
||||
## Install
|
||||
|
||||
Via Composer
|
||||
|
||||
``` bash
|
||||
$ composer require dnoegel/php-xdg-base-dir
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` php
|
||||
$xdg = \XdgBaseDir\Xdg();
|
||||
|
||||
echo $xdg->getHomeDir();
|
||||
echo $xdg->getHomeConfigDir()
|
||||
echo $xdg->getHomeDataDir()
|
||||
echo $xdg->getHomeCacheDir()
|
||||
echo $xdg->getRuntimeDir()
|
||||
|
||||
$xdg->getDataDirs() // returns array
|
||||
$xdg->getConfigDirs() // returns array
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
``` bash
|
||||
$ phpunit
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](https://github.com/dnoegel/php-xdg-base-dir/blob/master/LICENSE) for more information.
|
17
vendor/dnoegel/php-xdg-base-dir/composer.json
vendored
Normal file
17
vendor/dnoegel/php-xdg-base-dir/composer.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "dnoegel/php-xdg-base-dir",
|
||||
"description": "implementation of xdg base directory specification for php",
|
||||
"type": "project",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "@stable"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"XdgBaseDir\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
24
vendor/dnoegel/php-xdg-base-dir/phpunit.xml.dist
vendored
Normal file
24
vendor/dnoegel/php-xdg-base-dir/phpunit.xml.dist
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="php-xdg-base-dir unit tests">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
121
vendor/dnoegel/php-xdg-base-dir/src/Xdg.php
vendored
Normal file
121
vendor/dnoegel/php-xdg-base-dir/src/Xdg.php
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace XdgBaseDir;
|
||||
|
||||
/**
|
||||
* Simple implementation of the XDG standard http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
*
|
||||
* Based on the python implementation https://github.com/takluyver/pyxdg/blob/master/xdg/BaseDirectory.py
|
||||
*
|
||||
* Class Xdg
|
||||
* @package ShopwareCli\Application
|
||||
*/
|
||||
class Xdg
|
||||
{
|
||||
const S_IFDIR = 040000; // directory
|
||||
const S_IRWXO = 00007; // rwx other
|
||||
const S_IRWXG = 00056; // rwx group
|
||||
const RUNTIME_DIR_FALLBACK = 'php-xdg-runtime-dir-fallback-';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHomeDir()
|
||||
{
|
||||
return getenv('HOME') ?: (getenv('HOMEDRIVE') . DIRECTORY_SEPARATOR . getenv('HOMEPATH'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHomeConfigDir()
|
||||
{
|
||||
$path = getenv('XDG_CONFIG_HOME') ?: $this->getHomeDir() . DIRECTORY_SEPARATOR . '.config';
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHomeDataDir()
|
||||
{
|
||||
$path = getenv('XDG_DATA_HOME') ?: $this->getHomeDir() . DIRECTORY_SEPARATOR . '.local' . DIRECTORY_SEPARATOR . 'share';
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigDirs()
|
||||
{
|
||||
$configDirs = getenv('XDG_CONFIG_DIRS') ? explode(':', getenv('XDG_CONFIG_DIRS')) : array('/etc/xdg');
|
||||
|
||||
$paths = array_merge(array($this->getHomeConfigDir()), $configDirs);
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDataDirs()
|
||||
{
|
||||
$dataDirs = getenv('XDG_DATA_DIRS') ? explode(':', getenv('XDG_DATA_DIRS')) : array('/usr/local/share', '/usr/share');
|
||||
|
||||
$paths = array_merge(array($this->getHomeDataDir()), $dataDirs);
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHomeCacheDir()
|
||||
{
|
||||
$path = getenv('XDG_CACHE_HOME') ?: $this->getHomeDir() . DIRECTORY_SEPARATOR . '.cache';
|
||||
|
||||
return $path;
|
||||
|
||||
}
|
||||
|
||||
public function getRuntimeDir($strict=true)
|
||||
{
|
||||
if ($runtimeDir = getenv('XDG_RUNTIME_DIR')) {
|
||||
return $runtimeDir;
|
||||
}
|
||||
|
||||
if ($strict) {
|
||||
throw new \RuntimeException('XDG_RUNTIME_DIR was not set');
|
||||
}
|
||||
|
||||
$fallback = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::RUNTIME_DIR_FALLBACK . getenv('USER');
|
||||
|
||||
$create = false;
|
||||
|
||||
if (!is_dir($fallback)) {
|
||||
mkdir($fallback, 0700, true);
|
||||
}
|
||||
|
||||
$st = lstat($fallback);
|
||||
|
||||
# The fallback must be a directory
|
||||
if (!$st['mode'] & self::S_IFDIR) {
|
||||
rmdir($fallback);
|
||||
$create = true;
|
||||
} elseif ($st['uid'] != getmyuid() ||
|
||||
$st['mode'] & (self::S_IRWXG | self::S_IRWXO)
|
||||
) {
|
||||
rmdir($fallback);
|
||||
$create = true;
|
||||
}
|
||||
|
||||
if ($create) {
|
||||
mkdir($fallback, 0700, true);
|
||||
}
|
||||
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
}
|
116
vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php
vendored
Normal file
116
vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php
vendored
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
class XdgTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return \XdgBaseDir\Xdg
|
||||
*/
|
||||
public function getXdg()
|
||||
{
|
||||
return new \XdgBaseDir\Xdg();
|
||||
}
|
||||
|
||||
public function testGetHomeDir()
|
||||
{
|
||||
putenv('HOME=/fake-dir');
|
||||
$this->assertEquals('/fake-dir', $this->getXdg()->getHomeDir());
|
||||
}
|
||||
|
||||
public function testGetFallbackHomeDir()
|
||||
{
|
||||
putenv('HOME=');
|
||||
putenv('HOMEDRIVE=C:');
|
||||
putenv('HOMEPATH=fake-dir');
|
||||
$this->assertEquals('C:/fake-dir', $this->getXdg()->getHomeDir());
|
||||
}
|
||||
|
||||
public function testXdgPutCache()
|
||||
{
|
||||
putenv('XDG_DATA_HOME=tmp/');
|
||||
putenv('XDG_CONFIG_HOME=tmp/');
|
||||
putenv('XDG_CACHE_HOME=tmp/');
|
||||
$this->assertEquals('tmp/', $this->getXdg()->getHomeCacheDir());
|
||||
}
|
||||
|
||||
public function testXdgPutData()
|
||||
{
|
||||
putenv('XDG_DATA_HOME=tmp/');
|
||||
$this->assertEquals('tmp/', $this->getXdg()->getHomeDataDir());
|
||||
}
|
||||
|
||||
public function testXdgPutConfig()
|
||||
{
|
||||
putenv('XDG_CONFIG_HOME=tmp/');
|
||||
$this->assertEquals('tmp/', $this->getXdg()->getHomeConfigDir());
|
||||
}
|
||||
|
||||
public function testXdgDataDirsShouldIncludeHomeDataDir()
|
||||
{
|
||||
putenv('XDG_DATA_HOME=tmp/');
|
||||
putenv('XDG_CONFIG_HOME=tmp/');
|
||||
|
||||
$this->assertArrayHasKey('tmp/', array_flip($this->getXdg()->getDataDirs()));
|
||||
}
|
||||
|
||||
public function testXdgConfigDirsShouldIncludeHomeConfigDir()
|
||||
{
|
||||
putenv('XDG_CONFIG_HOME=tmp/');
|
||||
|
||||
$this->assertArrayHasKey('tmp/', array_flip($this->getXdg()->getConfigDirs()));
|
||||
}
|
||||
|
||||
/**
|
||||
* If XDG_RUNTIME_DIR is set, it should be returned
|
||||
*/
|
||||
public function testGetRuntimeDir()
|
||||
{
|
||||
putenv('XDG_RUNTIME_DIR=/tmp/');
|
||||
$runtimeDir = $this->getXdg()->getRuntimeDir();
|
||||
|
||||
$this->assertEquals(is_dir($runtimeDir), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* In strict mode, an exception should be shown if XDG_RUNTIME_DIR does not exist
|
||||
*
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetRuntimeDirShouldThrowException()
|
||||
{
|
||||
putenv('XDG_RUNTIME_DIR=');
|
||||
$this->getXdg()->getRuntimeDir(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* In fallback mode a directory should be created
|
||||
*/
|
||||
public function testGetRuntimeDirShouldCreateDirectory()
|
||||
{
|
||||
putenv('XDG_RUNTIME_DIR=');
|
||||
$dir = $this->getXdg()->getRuntimeDir(false);
|
||||
$permission = decoct(fileperms($dir) & 0777);
|
||||
$this->assertEquals(700, $permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure, that the fallback directories are created with correct permission
|
||||
*/
|
||||
public function testGetRuntimeShouldDeleteDirsWithWrongPermission()
|
||||
{
|
||||
$runtimeDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . XdgBaseDir\Xdg::RUNTIME_DIR_FALLBACK . getenv('USER');
|
||||
|
||||
rmdir($runtimeDir);
|
||||
mkdir($runtimeDir, 0764, true);
|
||||
|
||||
// Permission should be wrong now
|
||||
$permission = decoct(fileperms($runtimeDir) & 0777);
|
||||
$this->assertEquals(764, $permission);
|
||||
|
||||
putenv('XDG_RUNTIME_DIR=');
|
||||
$dir = $this->getXdg()->getRuntimeDir(false);
|
||||
|
||||
// Permission should be fixed
|
||||
$permission = decoct(fileperms($dir) & 0777);
|
||||
$this->assertEquals(700, $permission);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue