Download the PHP package davestewart/pathconfig without Composer

On this page you can find all versions of the php package davestewart/pathconfig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pathconfig

PathConfig

PathConfig allows a single point of configuration for your application's paths.

The library's main purpose it to allow restructuring of applications, working around framework's existing limitations.

The animation below demonstrates restructuring a Laravel 5 project to silo less-used components to a "support" folder:

path-config

The library provides both helper classes and Application class stubs to facilitate this.

Features

Configuration

Create a paths.php file in your project's root folder.

Return from it a single array with as many key/path pairs as your application requires:

All paths should be relative to the project root, which is determined separately.

Example configurations for Laravel 5.x and Lumen 5.x are available in the config/ folder.

For configuration-free instantiation, it is important that the config file remain in the root of the project!

Usage

There are 2 ways to use PathConfig:

  1. Standalone
  2. With Laravel or Lumen

Standalone

Load the PathConfig instance like so:

If a the basepath() option has not been set (the default) the library will search up the folder tree from it's vendor folder and look for the paths.php configuration file.

As soon as this has loaded, you're free to call get() methods on the $paths object as required.

With Laravel or Lumen

Assuming you have already copied and edited your configuration file there are 4 steps you need to take to refactor your app:

  1. Replace the default Application instance
  2. Physically move the framework folders
  3. Update some key path references
  4. Dump Composer's autoload

Firstly, you'll need to swap out your existing Illuminate Application class, with a pathconfig version that implements the new centralised path functionality, and overrides existing path-related methods.

In your application's bootstrap/app.php (or equivilent) file, replace the existing $app instantiation like so:

Make sure to use the appropriate class for your framework and version.

Secondly, make sure you physically move the folders on your hard disk, reflecting the paths in your config file.

Thirdly, update and and ALL framework files that may refer to your moved folders:

Laravel

File > location Search Replace
artisan bootstrap/ path to bootstrap
public/index.php ../bootstrap/ path to bootstrap
bootstrap/autoload.php ../vendor/ path to vendor
bootstrap/app.php $app = new Illuminate\Foundation\Application(...); $app = new pathconfig\apps\Laravel50; (or 51)
composer.json (autoload) database path to database
composer.json (autoload-dev) tests/ path to tests

Lumen

File > location Search Replace
artisan bootstrap/ path to bootstrap
public/index.php ../bootstrap/ path to bootstrap
bootstrap/app.php (autoload) ../vendor/ path to vendor
bootstrap/app.php (Dotenv) ../ path to root
bootstrap/app.php (Application) $app = new Laravel\Lumen\Application(...); $app = new pathconfig\apps\Lumen50;
bootstrap/app.php (Routes) require __DIR__.'/../app/Http/routes.php'; require $app->getPath('routes.php');
composer.json (autoload) database path to database
composer.json (autoload-dev) tests/ path to tests

Finally, dump Composer's autoload with composer dump-autoload.

At this point, you should be able to reload your application, and everything should just work.

Debugging it when it doesn't work first time

If your app errors, double-check your path edits (it's ALL about the path edits at this stage!) and make sure they are correct:

Getting and setting paths

Now you are up and running, you can start pulling paths out of your config.

Get paths directly from instance using the get() method:

To append an additional filepath (which also resolves any ../ references) add it as the second argument:

Passing a single argument that is NOT an existing path key resolves the path from the base folder:

Passing no arguments (or the word base) returns the base folder:

To get all paths, call all() method:

Pass false to return the same array, but with relative paths.

Set additional paths new path using set():

Options

There are various options to control the loading and conversion of paths.

By default they are set to mimic PHP's realpath() which outputs differently depending on the platform it's running on.

Set an alternative base path

To set a new base path:

Note that the base path can be set only before paths are loaded.

Convert slashes

To automatically convert slashes (on by default):

There are 3 options which include conversion of the base path, configured paths, and generated paths:

  1. true: convert all slashes to the platform type
  2. false: don't convert any slashes 3: 'auto' convert all slashes to the first slash type found in the config file

Trim trailing folder slashes

Some frameworks expect trailing slashes, some don't. To preserve trailing slashes passed in the config file (they are trimmed by default), call:

Note that none of the slash-related options will take effect after loading paths.

Test paths exist

By default the library doesn't test passed in paths to see if they exist in the way that PHP's realpath does. To mimic this behaviour call:

Allow paths to be set more than once

The library allows only allows you to set paths once, but you can override this by setting the mutable option to false:

Additional functionality

To alias the get() method as a global function

It might be incovenient to pass around a $paths variable. You can alias the method with a helper in one of two ways:

Manually:

Using the static alias() method:

Both methods will create a global helper method called path() than you can use from anywhere:

To load paths from a custom location

If you want to move your paths config file to a custom location, you'll need to set both the basepath and config paths manually:

Note that base paths should be absolute, but the config path:


All versions of pathconfig with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package davestewart/pathconfig contains the following files

Loading the files please wait ....