Download the PHP package metra/cascading-filesystem without Composer
On this page you can find all versions of the php package metra/cascading-filesystem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download metra/cascading-filesystem
More information about metra/cascading-filesystem
Files in metra/cascading-filesystem
Package cascading-filesystem
Short Description A virtual filesystem formed from merging multiple directories
License BSD-3-Clause
Informations about the package cascading-filesystem
Cascading Filesystem
Installation
Add this package as a dependency in your project's composer.json configuration:
Now run composer install
in the terminal at the root of your project.
You must then enable composer autoloading (if you haven't already) by requiring the autoload file:
For more information on composer please refer to its documentation.
Concept
The cascading filesystem (often abbreviated to CFS) is a collection of separate directory paths. The contents of these directories are virtually merged together creating the illusion that all of the the files are in the same directory. Files that are in latter defined directories take precedence over (and replace) files of the same location. This makes it is possible to overload any file simply by placing it in the same location of a latter directory.
For example, let's say we had these three directories in the cascading filesystem:
This would be the result when the directory's contents are virtually merged together:
Instantiation
Finding Files
This finds the file path with the highest precedence in the cascading filesystem and returns its absolute location:
You can also retrieve every location that the file exists, this would return an array of absolute file paths:
This lists the files of a directory in the merged CFS:
Modules
Modules are really just an extended concept of a directory in the cascading filesystem. The additional functionality a module gains is that it can be initialized and classes within it can be autoloaded. Modules provide an easy way to organize your code and make any part more shareable or transportable across different applications.
Initialization
To initialize all of the enabled modules in the cascading filesystem:
This should be done before you start using the modules as they may have prerequisites which are fulfilled by initialization.
Specification
If you would like your module to be initialized you must add an init.php
file at the root. When the user initializes all of their modules, this init file will be included into the PHP script. This is the ideal place to execute any PHP code necessary for the module to function.
Autoloading
To enable the autoloading of classes inside of modules you must first register the autoloader class by executing its register method:
There is also a backwards compatibility autoloader for module classes which still use the old file naming convention (lowercase):
Now the autoloader is registered you can go ahead and use any classes as if they're already included. There is also an unregister()
method for unregistering an autoloader after its registration. For more precise control over registering an autoloader, you may enable its autoload
method directly using spl_autoload_register()
.
Specification
All classes that need to be autoloaded must follow this specification:
- All classes must be placed in a
classes/
directory at the root of the module. - All classes must follow the PSR-0 standard.
- All class names must be capitalized, e.g.
Foo_Bar_Baz
,Teapot
,Hello_World
. - The class's filename and location must match the class's name exactly (including case). For example, the class
Foo_Bar_Baz
must be located atclasses/Foo/Bar/Baz.php
. - Any underscore characters in the class name are converted to slashes.
- All class names must be capitalized, e.g.
If your classes do not follow this convention, they cannot be autoloaded by this package. You would have to manually include your classes or create your own autoloader.
Where to Find Modules
-
kohana-modules - A website dedicated to indexing all Kohana modules with an excellent search and refine system; created by Andrew Hutchings.
- kohana-universe - A fairly comprehensive list of modules that are available on GitHub created by Kolanos. To get your module listed there, send him a message via GitHub.