-
Notifications
You must be signed in to change notification settings - Fork 11
Component Autoloader
alex_prokopenko edited this page Jan 16, 2018
·
2 revisions
This component is used to easily register autoloader (PSR-4: Autoloader) based on namespaces. Please check Getting Starter section for more details what are autoloader and namespaces.
This class can register matching between some directory on disk and namespace prefix.
To register autoloader for some namespace you should create new instance of Autoload class:
<?php
new \JustCoded\WP\Framework\Autoload( '{namespace prefix}', '/your/directory/path' );The plugin itself doesn't include any files except Autoload class. It just registers the specific namespace to plugin main folder. So if you don't use some base classes - they won't be loaded.
Plugin namespace registration looks like this:
<?php
require_once( dirname( __FILE__ ) . '/framework/Autoload.php' );
new JustCoded\WP\Framework\Autoload( 'JustCoded\WP\Framework', dirname( __FILE__ ) . '/framework' );Theme namespace registration example in {theme}/functions.php:
<?php
new \JustCoded\WP\Framework\Autoload( 'Boilerplate\Theme', get_template_directory() . '/app' );