Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loilo/storage-paths
🗄 Get OS-specific paths for storing your project's config, cache, logs etc.
https://github.com/loilo/storage-paths
Last synced: about 23 hours ago
JSON representation
🗄 Get OS-specific paths for storing your project's config, cache, logs etc.
- Host: GitHub
- URL: https://github.com/loilo/storage-paths
- Owner: loilo
- License: other
- Created: 2019-07-15T13:41:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-23T23:08:19.000Z (about 4 years ago)
- Last Synced: 2024-12-31T03:12:37.916Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
# Storage Paths
[](https://github.com/loilo/storage-paths/actions)
[](https://packagist.org/packages/loilo/storage-paths)This package yields OS-specific paths for storing your project's config, cache, logs etc. While the API has been adjusted for PHP, the research and opinionated fallbacks stem from the Node.js [env-paths](https://github.com/sindresorhus/env-paths) package by [Sindre Sorhus](https://github.com/sindresorhus).
## Install
```bash
composer require loilo/storage-paths
```## Usage
Example for macOS:```php
use Loilo\StoragePaths\StoragePaths;$paths = StoragePaths::for('MyApp');
$paths->data() === '/Users/loilo/Library/Application Support/MyApp-php';
$paths->config() === '/Users/loilo/Library/Preferences/MyApp-php';
$paths->cache() === '/Users/loilo/Library/Caches/MyApp-php';
$paths->log() === '/Users/loilo/Library/Logs/MyApp-php';
$paths->temp() === '/var/folders/qh/z_hny67s57sfm_sxy1zynnkr0000gn/T/MyApp-php';
```## API
### Signature
```php
StoragePaths::for(string $name, array $options): StoragePathsInterface;
```* `$name` — The name of your project. This is used to generate the paths, therefore it needs to be a valid filename.
* `$options` — An (optional) associative array of options:
* `$options['suffix']`**Type:** `string`
**Default:** `'php'`
A suffix string appended to the project name to avoid naming conflicts with native apps.
* `$options['os']`**Type:** `string`
**Default:** `PHP_OS_FAMILY`
Override the operating system to generate paths for. Values correspond to the [`PHP_OS_FAMILY`](https://www.php.net/manual/reserved.constants.php#constant.php-os-family) constant.> **Note:** Calling `StoragePaths::for()` only generates the path strings. It doesn't create the directories for you.
### Result
The returned [`StoragePathsInterface`](src/StoragePathsInterface.php) provides access to the following storage methods:* `data()` — Directory for data files
* `config()` — Directory for config files
* `cache()` — Directory for for non-essential data files
* `log()` — Directory for log files
* `temp()` — Directory for temporary files