Git Product home page Git Product logo

php-xdg-base-dir's People

Contributors

bcremer avatar bobthecow avatar dnoegel avatar grahamcampbell avatar haehnchen avatar kasperfranz avatar krageon avatar luukverhoeven avatar ntoniazzi avatar nubs avatar reedy avatar theofidry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-xdg-base-dir's Issues

Invalid home directory

I originally noticed (and reported) this issue in PsySh. The original issue: bobthecow/psysh#382

So basically, Xdg isn't getting the home directory correctly:

getHomeDir: /
getHomeConfigDir: //.config
getHomeDataDir: //.local/share
getConfigDirs: Array ( [0] => //.config [1] => /etc/xdg ) 
getDataDirs: Array ( [0] => //.local/share [1] => /usr/local/share [2] => /usr/share ) 
getHomeCacheDir: //.cache

This is on a CentOS 6.9 machine. Tested it on my MacBook and it works just as expected.

Any ideas?

PhpUnit 7 Support

Hi,

i wanted to run phpunit in my laravel 5.8 project and saw that this library doesn't support PhpUnit 7. I'm using "phpunit/phpunit": "^7.5" at the moment.

Here's a related comment describing the problem.
symfony/symfony#21816 (comment)

Are there any plans to update the unit test to be compatible with 7.5 ?

Stack

vagrant@alpha-api:~/code$ phpunit .
PHP Fatal error:  Uncaught Error: Class 'PHPUnit_Framework_TestCase' not found in /home/vagrant/code/vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php:3
Stack trace:
#0 /home/vagrant/code/vendor/phpunit/phpunit/src/Util/FileLoader.php(57): include_once()
#1 /home/vagrant/code/vendor/phpunit/phpunit/src/Util/FileLoader.php(45): PHPUnit\Util\FileLoader::load('/home/vagrant/c...')
#2 /home/vagrant/code/vendor/phpunit/phpunit/src/Framework/TestSuite.php(540): PHPUnit\Util\FileLoader::checkAndLoad('/home/vagrant/c...')
#3 /home/vagrant/code/vendor/phpunit/phpunit/src/Framework/TestSuite.php(618): PHPUnit\Framework\TestSuite->addTestFile('/home/vagrant/c...')
#4 /home/vagrant/code/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(70): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#5 /home/vagrant/code/vendor/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest('.', '', Array)
#6 /home/vagrant/code/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#7 /hom in /home/vagrant/code/vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php on line 3

Fatal error: Uncaught Error: Class 'PHPUnit_Framework_TestCase' not found in /home/vagrant/code/vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php:3
Stack trace:
#0 /home/vagrant/code/vendor/phpunit/phpunit/src/Util/FileLoader.php(57): include_once()
#1 /home/vagrant/code/vendor/phpunit/phpunit/src/Util/FileLoader.php(45): PHPUnit\Util\FileLoader::load('/home/vagrant/c...')
#2 /home/vagrant/code/vendor/phpunit/phpunit/src/Framework/TestSuite.php(540): PHPUnit\Util\FileLoader::checkAndLoad('/home/vagrant/c...')
#3 /home/vagrant/code/vendor/phpunit/phpunit/src/Framework/TestSuite.php(618): PHPUnit\Framework\TestSuite->addTestFile('/home/vagrant/c...')
#4 /home/vagrant/code/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(70): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#5 /home/vagrant/code/vendor/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest('.', '', Array)
#6 /home/vagrant/code/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#7 /hom in /home/vagrant/code/vendor/dnoegel/php-xdg-base-dir/tests/XdgTest.php on line 3

Add ability to lookup a file

The getConfigDirs and getDataDirs methods are useful for looking up a file, but it would be nice if the library also provided a getConfigFile($relativePath) (and similar for data/cache/runtime files) that would walk the directory list and return the full path to the first one found, or null if none of the directories include the file).

Do not remove invalid runtime dir, throw exception instead

I don't like how an "invalid" runtime directory is unliked at the moment (https://github.com/dnoegel/php-xdg-base-dir/blob/master/src/Xdg.php#L105).

Instead I would like to throw an exception like throw new RuntimeException('Unsecure Runtime dir').
See also this example: https://github.com/o11c/rust-xdg/blob/master/src/xdg.rs#L52

public function getRuntimeDir($strict=true) could become public function getRuntimeDir($create = true, $forceSecure = true).

Feedback welcome.

Add a LICENSE

I'm assuming this is licensed under the MIT license (based off of the composer.json file), but including the full license text with a copyright line (e.g., here) helps clear up the legal standing of this code.

rmdir() failing on directory not empty

I'm trying to use psysh which uses 0.1 of this library and each time I run it I get:

PHP Warning:  rmdir(/var/folders/.../T/php-xdg-runtime-dir-fallback-mschinkel): Directory not empty in phar:///usr/local/bin/psysh/build-vendor/dnoegel/php-xdg-base-dir/src/Xdg.php on line 110
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/psysh:0
PHP   2. Psy\{closure}() /usr/local/bin/psysh:141
PHP   3. Psy\Shell->run() phar:///usr/local/bin/psysh/src/Psy/functions.php:325
PHP   4. Psy\Shell->initializeTabCompletion() phar:///usr/local/bin/psysh/src/Psy/Shell.php:247
PHP   5. Psy\Shell->addTabCompletionMatchers() phar:///usr/local/bin/psysh/src/Psy/Shell.php:990
PHP   6. Psy\Shell->getTabCompletionMatchers() phar:///usr/local/bin/psysh/src/Psy/Shell.php:224
PHP   7. Psy\Shell->all() phar:///usr/local/bin/psysh/src/Psy/Shell.php:200
PHP   8. Psy\Shell->init() phar:///usr/local/bin/psysh/build-vendor/symfony/console/Application.php:641
PHP   9. Psy\Shell->getDefaultCommands() phar:///usr/local/bin/psysh/build-vendor/symfony/console/Application.php:1163
PHP  10. Psy\Configuration->getRuntimeDir() phar:///usr/local/bin/psysh/src/Psy/Shell.php:185
PHP  11. Psy\ConfigPaths::getRuntimeDir() phar:///usr/local/bin/psysh/src/Psy/Configuration.php:348
PHP  12. XdgBaseDir\Xdg->getRuntimeDir() phar:///usr/local/bin/psysh/src/Psy/ConfigPaths.php:153
PHP  13. rmdir() phar:///usr/local/bin/psysh/build-vendor/dnoegel/php-xdg-base-dir/src/Xdg.php:110

Looking at your code on line 110 it seems you are doing an rmdir() on a directory containing files.

Maybe you could replace with this from StackOverflow?

getRuntimeDir() fails when used with sudo

getRuntimeDir() returns the value of XDG_RUNTIME_DIR when available. When using sudo -E (something that can happen easily on a typical web host, as people running scripts manually need to sudo to the same user that the web server uses, to avoid file permission headaches, and the environment might be required for token checks or language settings or similar), XDG_RUNTIME_DIR will point to the temp directory of the original user, so the user which the script is running at won't be able to write the tempdir.

E.g. on a server with someuser and webuser users, where someuser has user ID 1 and webuser has user ID 2, when someuser executes sudo -E -u webuser foo.php and foo.php calls Xdg::getRuntimeDir(), in the environment of someuser XDG_RUNTIME_DIR will be /run/user/1, and sudo inherits the environment, so Xdg::getRuntimeDir() will return that directory, but /run/user/1 is owned by someuser with permission 700, so foo.php will fail to write it.

Some kind of sanity check of the current user vs. the user ID in XDG_RUNTIME_DIR would be nice.

Tag a version

Could you tag this at a version (I'd recommend 0.1.0 or 1.0.0 as per semver). That would make it easier to including using composer (no need to use a "dev" stability setting).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.