Coder Social home page Coder Social logo

remicollet / classloader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from symfony/class-loader

0.0 3.0 0.0 419 KB

[READ-ONLY] Subtree split of the Symfony ClassLoader Component -- clone into Symfony/Component/ (master at symfony/symfony)

Home Page: http://symfony.com/

License: MIT License

PHP 100.00%

classloader's Introduction

ClassLoader Component

ClassLoader loads your project classes automatically if they follow some standard PHP conventions.

The ClassLoader object is able to autoload classes that implement the PSR-0 standard or the PEAR naming convention.

First, register the autoloader:

require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';

use Symfony\Component\ClassLoader\ClassLoader;

$loader = new ClassLoader();
$loader->register();

Then, register some namespaces with the addPrefix() method:

$loader->addPrefix('Symfony', __DIR__.'/src');
$loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src');

The addPrefix() method takes a namespace prefix and a path where to look for the classes as arguments.

You can also register a sub-namespaces:

$loader->addPrefix('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');

The order of registration is significant and the first registered namespace takes precedence over later registered one.

You can also register more than one path for a given namespace:

$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));

Alternatively, you can use the addPrefixes() method to register more than one namespace at once:

$loader->addPrefixes(array(
    'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
    'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
    'Doctrine' => __DIR__.'/vendor/doctrine/lib',
    'Monolog' => __DIR__.'/vendor/monolog/src',
));

For better performance, you can use the APC class loader:

require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';

use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\ApcClassLoader;

$loader = new ClassLoader();
$loader->addPrefix('Symfony', __DIR__.'/src');

$loader = new ApcClassLoader('apc.prefix.', $loader);
$loader->register();

Furthermore, the component provides tools to aggregate classes into a single file, which is especially useful to improve performance on servers that do not provide byte caches.

Resources

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/ClassLoader/
$ composer install
$ phpunit

classloader's People

Contributors

artemdigi avatar bamarni avatar cordoval avatar craue avatar dlsniper avatar dustinwhittle avatar fabpot avatar gajdaw avatar grahamcampbell avatar hason avatar igorw avatar jfsimon avatar kimhemsoe avatar kriswallsmith avatar larowlan avatar lologhi avatar lsmith77 avatar merk avatar nicolas-grekas avatar pborreli avatar rouffj avatar saro0h avatar seldaek avatar stloyd avatar stof avatar tobion avatar vicb avatar willdurand avatar xabbuh avatar yrwein avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.