Permalink
Browse files

Add an autoloader to use the snappy standalone.

  • Loading branch information...
GromNaN committed Dec 3, 2011
1 parent e8c33c8 commit b3261042aa61f387ca6f78b9444e4fee7239b799
Showing with 24 additions and 20 deletions.
  1. +2 −0 README.markdown
  2. +1 −1 phpunit.xml.dist
  3. +21 −0 src/autoload.php
  4. +0 −19 test/bootstrap.php
View
@@ -11,6 +11,8 @@ You will have to download wkhtmltopdf 0.10.0 >= rc2 in order to use Snappy.
```php
<?php
+require_once '/path/to/snappy/src/autoload.php';
+
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
View
@@ -9,7 +9,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
- bootstrap="test/bootstrap.php"
+ bootstrap="src/autoload.php"
>
<testsuites>
<testsuite name="Snappy Test Suite">
View
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
+ * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
+ *
+ * Code inspired from the SplClassLoader RFC
+ * @see https://wiki.php.net/rfc/splclassloader#example_implementation
+ */
+spl_autoload_register(function($className) {
+ $package = 'Knp\\Snappy';
+ $className = ltrim($className, '\\');
+ if (0 === strpos($className, $package)) {
+ $fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
+ if (is_file($fileName)) {
+ require $fileName;
+ return true;
+ }
+ }
+ return false;
+});
View
@@ -1,19 +0,0 @@
-<?php
-
-spl_autoload_register(
- function($class) {
- static $classes = null;
- if ($classes === null) {
- $classes = array(
- 'knp\\snappy\\generatorinterface' => '/GeneratorInterface.php',
- 'knp\\snappy\\abstractgenerator' => '/AbstractGenerator.php',
- 'knp\\snappy\\image' => '/Image.php',
- 'knp\\snappy\\pdf' => '/Pdf.php'
- );
- }
- $cn = strtolower($class);
- if (isset($classes[$cn])) {
- require __DIR__ . '/../src/Knp/Snappy' . $classes[$cn];
- }
- }
-);

0 comments on commit b326104

Please sign in to comment.