Skip to content

Instantly share code, notes, and snippets.

@eniuz
Created April 28, 2015 09:36
Show Gist options
  • Save eniuz/828971717b376872b06c to your computer and use it in GitHub Desktop.
Save eniuz/828971717b376872b06c to your computer and use it in GitHub Desktop.
Faster Autoload
<?php
/**
* This code has being taken from Patrick Allert's article:
*/
spl_autoload_register(
function ( $className )
{
if (
strpos( $className, "Symfony\\" ) === 0 ||
strpos( $className, "Sensio\\" ) === 0 ||
strpos( $className, "eZ\\" ) === 0 ||
strpos( $className, "EzSystems\\" ) === 0 ||
strpos( $className, "Monolog\\" ) === 0 ||
strpos( $className, "Psr\\" ) === 0 ||
strpos( $className, "Twig_" ) === 0 ||
strpos( $className, "Assetic\\" ) === 0
)
{
if (
file_exists(
$path = __DIR__ . "/../vendor/PSR-0/" . str_replace( array( "_", "\\" ), "/", $className ) . ".php"
)
)
{
require $path;
}
}
else
{
return;
}
},
true
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment