Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an autoloader to use the snappy standalone. #24

Merged
merged 1 commit into from Dec 3, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.markdown
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -9,7 +9,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="test/bootstrap.php"
bootstrap="src/autoload.php"
>
<testsuites>
<testsuite name="Snappy Test Suite">
Expand Down
21 changes: 21 additions & 0 deletions src/autoload.php
@@ -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;
});
19 changes: 0 additions & 19 deletions test/bootstrap.php

This file was deleted.