A library providing platform-specific user directory paths, such as config and cache

Overview

Phirs

Continuous Integration

A library providing platform-specific user directory paths, such as config and cache. Inspired by dirs-rs.

Features

  • Multiple Platform. Providing cross-platform paths, plus platform-specific ones. Make your app run-everywhere or target a specific platform. See Platform Support for more details.

  • Hackable. Adding support for a specific platform is easy.

  • Well-Designed. Provide good design and simple abstractions (with the help of powerful PHP interfaces and traits).

  • Well-Tested. Many pieces of the library are covered by unit tests. With the help of CI tools also, it is continuously tested againts major platforms.

Why?

When writing a console application (or even a graphical one; who knows, people might start writing graphical applications in PHP in near future), sometimes you need to have a location to:

  • store your configurations, and possibly re-use them in the future runs,
  • make cache files and improve the performance of your application,
  • create a media and put it somewhere reasonable,
  • etc.

For the best results, the locations should be cross-platform, permanent, accessible (i.e. both readable and writable), well-known and non-relative.

Phirs can help you in these situations.

Note: The library does not guarantee that all provided paths meet all the conditions above, although it helps you achieving them. The reason is performance, and the fact that different users may have different needs (e.g. one may check for a path to exist, one may suppose it to exist). Theoretically, in a standard environment and for standard paths, all these conditions are met (although the directories might not actually exist).

But There Is Another Library!

Why not just using Basedir?

Go back and see features. Having these there would require a major rewrite and huge backward-compatibility break. Plus, Basedir is no longer available on Packagist, for some unknown reason.

Requirements

PHP 7.4+ only.

Installation

Easy like every other PHP library:

composer install machitgarha/phirs

Basic Usage

A simple use for most common cases is the following:

use MAChitgarha\Phirs\DirectoryProviderFactory;
use MAChitgarha\Phirs\Util\Platform;

// Get a provider for the current platform
$dirProvider = DirectoryProviderFactory::createStandard(Platform::autoDetect());

// Let's get some paths!
$configPath = $dirProvider->getConfigPath();
$docsPath = $dirProvider->getDocumentsPath();

// Load or save something…!

What a provider is? Why we use createStandard()? Can I extend it and map a specific platform to my own provider? See Usage Guide for more details.

Platform Support

Platform Having a Provider? Supported? Working? Having a Specialized Provider?
GNU/Linux distributions
Windows
Mac OS
Termux on Android (1)
BSD
Solaris
Android
iOS
  • : Has notes.
  • : Not known or depends on the environment.
  • : Like , but most likely no.

Notes

  1. It might not be exactly what you or users expect; e.g. pictures directory path is inside Termux home, not the internal SDCard (i.e. /sdcard).

Contribute!

In a world like this, everyone should be a contributor. So, start helping this project by creating an issue, forking and improving it, or simply introducing it to your PHP developer friends!

If you want to get an overall overview of the code, go and read Usage Guide.

For the best results, see Contribution Guidelines.

License

The project is licensed under Apache 2.0 License.

You might also like...
Doctrine Cache component

Doctrine Cache Cache component extracted from the Doctrine Common project. Documentation This library is deprecated and will no longer receive bug fix

LRU Cache implementation in PHP

PHP LRU Cache implementation Intro WTF is a LRU Cache? LRU stands for Least Recently Used. It's a type of cache that usually has a fixed capacity and

Simple cache abstraction layer implementing PSR-16

sabre/cache This repository is a simple abstraction layer for key-value caches. It implements PSR-16. If you need a super-simple way to support PSR-16

PSR-6 cache implementation adapting a given PSR-16 instance

PSR-6 cache implementation adapting PSR-16 This package provides a PSR-6 cache instance when you only have a PSR-16 cache at hand. As PSR-6 is more fe

More Than Just a Cache: Redis Data Structures
More Than Just a Cache: Redis Data Structures

More Than Just a Cache: Redis Data Structures Redis is a popular key-value store, commonly used as a cache or message broker service. However, it can

Simple cache

Simple cache

Elephant - a highly performant PHP Cache Driver for Kirby 3

🐘 Kirby3 PHP Cache-Driver Elephant - a highly performant PHP Cache Driver for Kirby 3 Commerical Usage Support open source! This plugin is free but i

An improved helper for working with cache

Laravel Cache Installation To get the latest version of Laravel Cache, simply require the project using Composer: $ composer require dragon-code/larav

Releases(0.1.0)
Owner
Mohammad Amin Chitgarha
FOSS lover. Trying to be a full-time open-source developer. Student at Bu-Ali Sina university.
Mohammad Amin Chitgarha
A fast, lock-free, shared memory user data cache for PHP

Yac is a shared and lockless memory user data cache for PHP.

Xinchen Hui 815 Dec 18, 2022
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

DataLoaderPHP is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

Webedia - Overblog 185 Nov 3, 2022
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

Donate/Support: Documentation: https://www.scrapbook.cash - API reference: https://docs.scrapbook.cash Table of contents Installation & usage Adapters

Matthias Mullie 295 Nov 28, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache implementation of that

Cache Async, Promise-based cache interface for ReactPHP. The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache imple

ReactPHP 330 Dec 6, 2022
LaraCache is an ORM based package for Laravel to create, update and manage cache items based on model queries

LaraCache Using this package, you can cache your heavy and most used queries. All you have to do is to define the CacheEntity objects in the model and

Mostafa Zeinivand 202 Dec 19, 2022
The place to keep your cache.

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Tedious Developments 944 Jan 4, 2023
Cache slam defense using a semaphore to prevent dogpile effect.

metaphore PHP cache slam defense using a semaphore to prevent dogpile effect (aka clobbering updates, stampending herd or Slashdot effect). Problem: t

Przemek Sobstel 102 Sep 28, 2022
:zap: Simple Cache Abstraction Layer for PHP

⚡ Simple Cache Class This is a simple Cache Abstraction Layer for PHP >= 7.0 that provides a simple interaction with your cache-server. You can define

Lars Moelleken 27 Dec 8, 2022