Table of Contents
Descriptor Auto-loading
Descriptor Auto-loading is a feature that let's your package end users load your packages with fewer lines or character of code with the simple class method
call
$this->load->package("vendor/package_name");
All you have to do to make this possible is by using the autoload
key in your package descriptor (splint.json
) file. You can use this file to autoload the following resource types.
- Libraries (PHP Classes)
- Models
- Helpers &
- Configs
Auto-loading Libraries (Classes)
No Constructor Parameter
{ "autoload": { "libraries": [ ["ClassName", "alias"] ] } }
With Constructor Parameters
{ "autoload": { "libraries: [ ["ClassName", {"arg1" => "val1", "arg2" => "val2"}, "alias"] ] } }
With Config File
{ "autoload": { "libraries": [ ["ClassName", "@config_file_name", "alias"] ] } }
The end user will have to create a config file located at application/config/config_file_name.php
to contain the following.
<?php defined('BASEPATH') OR exit('No direct script access allowed'); $config["config_file_name"] = [ "arg1" => "value1", "arg2" => "value2", "argN" => "valueN" ] ?>
Notice that thekey
of the array in the$config
variable is the same as the name of the config file.
Splint will not throw an Exception if this file doesn't exist. You must check the argument array in your class constructor and verify use theisset()
function to check for present values.
Auto-loading Models
{ "autoload": { "models": [ ["ModelClassName", "alias"] ] } }
Auto-loading Helpers
{ "autoload": { "helpers": [ ["helper1", "helper2", "helperN"] ] } }
Auto-loading Configs
{ "autoload": { "configs": [ ["config1", "config2", "configN"] ] } }
Conclusion
With this, developers should indicate in their README files what they used as their aliases
for the resources loaded. (If they used descriptor auto-loading). so end users can go ahead and do something like the one below.
// Quick Load Library. $this->load->package("splint/platform"); // Use loaded resources (Library Class for Instance). $this->alias->some_method();