lum / lum-core
Lum Core library and plugins
Requires
- lum/lum-compat: ^2.6
Requires (Dev)
- lum/lum-test: ^3.0
Suggests
- lum/lum-core-plugins: A full set of Core plugins
- dev-main / 3.x-dev
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-dev-split-3
- dev-master
This package is auto-updated.
Last update: 2024-11-10 23:32:31 UTC
README
Summary
A small class with a singleton instance that can be used to manage the lifecycle of a PHP application, acting as a director for models, controllers, and views.
It also supports additional plugins that have a ton of extra functionality.
Despite the name of the package and class, this is not in fact the singular
core library that everything else in the Lum.php collections builds upon.
It used to be in the 1.x
days, but has since become just the App Director
singleton class. See lum-compat
for the true fundamental core class that the whole PHP library set uses.
Classes
Traits
Note on Plugins
Prior to v3.0
most of the additional plugins were included in the core
package itself, but I decided that it made more sense to split them off into
their own packages. A suggested
lum-core-plugins
meta-package will be available to install all of the plugins that used to
be included in this package.
Creating a Core instance
You only need to do this once in your application, generally right at the
beginning (either at the very top of the main PHP script, or right after
a namespace
declaration if the script itself is inside a PHP Namespace.)
require_once 'vendor/autoload.php'; // Register Composer autoloaders. \Lum\Autoload::register(); // If using spl_autoload, call this. $core = \Lum\Core::getInstance(); // Create your Core object.
The first line is a standard for anything using Composer, and the
second line is a compatibility function from lum-compat
that allows
the use of classic SPL autoloading along side Composer autoloading.
The last line is the one that actually creates the singleton instance.
You cannot use the new \Lum\Core()
style constructor with this class.
The constructor is protected and can only be called via getInstance()
.
Getting the current Core instance
Any time you need the Core, you simply call the getInstance()
method.
$core = \Lum\Core::getInstance(); // Return the current core instance.
Since this is using a singleton instance, it will always return the same object no matter where or how many times it is called.
Using plugins
The plugins are loaded automatically when first called. For instance:
$lum = \Lum\Core::getInstance(); $lum->conf->setDir('./conf'); // Load Conf plugin and call setDir() on it. $lum->router = ['extend'=>true, 'auto_prefix'=>true]; // Load Router plugin. $lum->router->loadRoutes($lum->conf->routes); // Load routes into Router. $lum->controllers->addNS("\\MyApp\\Controllers"); // Load Controllers plugin. $lum->models->addNS("\\MyApp\\Models"); // Load Models plugin. $lum->controllers->use_screens(); // Use default view loaders. $lum->dispatch(); // Call an extension method added by Router plugin.
The above example is written assuming lum-core-plugins
is also installed,
as the conf
and router
plugins have been split into their own packages
and are no longer included by default, but lum-core-plugins
includes all
of the split-off plugins.
Official URLs
This library can be found in two places:
Author
Timothy Totten