2017 © Pedro Peláez
 

library class-loader

Webiny Class Loader Component

image

webiny/class-loader

Webiny Class Loader Component

  • Friday, September 29, 2017
  • by SvenAlHamad
  • Repository
  • 2 Watchers
  • 1 Stars
  • 168 Installations
  • PHP
  • 16 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 24 Versions
  • 0 % Grown

The README.md

ClassLoader Component

Class loader component loads your PHP files automatically as long as they follow some standard naming convention. The following standards are supported: - PEAR - PSR-0 - PSR-4, (*1)

Install the component

The best way to install the component is using Composer., (*2)

composer require webiny/class-loader

For additional versions of the package, visit the Packagist page., (*3)

Usage

To use the ClassLoader, get its instance by calling ClassLoader::getInstance() method., (*4)

    require_once 'Webiny/Component/ClassLoader/ClassLoader.php'

    use Webiny\Component\ClassLoader;

    ClassLoader::getInstance();

Once you have the ClassLoader instance, you can register map rules. The ClassLoader automatically detects if you are registering a namespace or a PEAR rule. PEAR rules are identified by having a underline '_' at the end of the prefix. If PSR is not defined, the component will use PSR-4 standard. All paths should be absolute., (*5)

    ClassLoader::getInstance()->registerMap([
                                            // a namespace rule (PSR-4 - default)
                                            'Webiny' => realpath(dirname(__FILE__)).'/library/Webiny',
                                            // a namespace rule (PSR-0)
                                            'Symfony' => [
                                                'Path' => '/var/vendors/Symfony',
                                                'Psr' => 0
                                            ],
                                            // a PEAR rule
                                            'Swift_' => realpath(dirname(__FILE__)).'/library/Swift',
                                            ]);

As you can see the registerMap method takes an array of multiple rules. Each rule consists of a prefix and a location., (*6)

For better performance you can provide a Cache component to ClassLoader. Doing so, ClassLoader will cache the paths and files resulting in a faster performance., (*7)

    ClassLoader::getLoader()->registerCacheDriver($instanceOfCacheInterface);

Non-standardized libraries

If you have a library that is not following neither the PSR naming convention nor the PEAR naming convention, you'll have to manually define some of the settings., (*8)

Let's take a look at this example:, (*9)

    ClassLoader::getInstance()->registerMap([
        'Smarty_' => [
                        'Path'      => '/var/www/Vendors/Smarty/libs/sysplugins',
                        'Normalize' => false,
                        'Case'      => lower
                     ]
    ]);

You can see that the Smarty_ library is defined as an array that has Path, Normalize and Case parameter., (*10)

Path

Defines the path to the library., (*11)

Normalize

The Normalize parameter tells the autoloader if he should to change the _, on the class name, into directory separators. For example if you have a class namesSmarty_Internal_Compile the normalized path would be Smarty/Internal/Compiler. If you set the Normalize parameter to false, the original class name will be used., (*12)

Case

By default the autoloader transfers all the class names to CamelCase, you can set the Case parameter to lower if you wish that the class names are used in lower case inside the class path., (*13)

Resources

To run unit tests, you need to use the following command:, (*14)

$ cd path/to/Webiny/Component/ClassLoader/
$ composer.phar install
$ phpunit

The Versions

29/09 2017

dev-master

9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

29/09 2017

1.6.x-dev

1.6.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

29/09 2017

v1.6.0

1.6.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

29/09 2017

v1.6.1

1.6.1.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

08/09 2017

1.5.x-dev

1.5.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

08/09 2017

v1.5.0

1.5.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

21/08 2016

1.4.x-dev

1.4.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

21/08 2016

v1.4.3

1.4.3.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

04/02 2016

v1.4.0

1.4.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

04/02 2016

v1.4.1

1.4.1.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

04/02 2016

v1.4.2

1.4.2.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

16/03 2015

1.3.x-dev

1.3.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

16/03 2015

v1.3.0

1.3.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

05/02 2015

v1.2.2

1.2.2.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

05/02 2015

v1.2.3

1.2.3.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

05/02 2015

v1.2.1

1.2.1.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

04/02 2015

1.2.x-dev

1.2.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

04/02 2015

v1.2.0

1.2.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

17/01 2015

v1.1.2

1.1.2.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

28/11 2014

v1.1.1

1.1.1.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

23/11 2014

1.1.x-dev

1.1.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

23/11 2014

v1.1.0

1.1.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

19/09 2014

1.0.x-dev

1.0.9999999.9999999-dev http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader

19/09 2014

v1.0.0

1.0.0.0 http://www.webiny.com/

Webiny Class Loader Component

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sven Al Hamad
by Pavel Denisjuk

autoloader psr-4 psr-0 class loader