Getting Started Loading components and error handling

Loading Components

No file of the SetaPDF 2 components is using include(), require() or a simliar statement to load a class/file. All PHP classes/files loading is done via a single autoload function which will be registered automatically as an __autoload() implementation with spl_autoload_register when the file /library/SetaPDF/Autoload.php is required once:

PHP
require_once('/absolute/path/to/library/SetaPDF/Autoload.php');

or

PHP
require_once('../relative/path/to/library/SetaPDF/Autoload.php');

After that all PHP classes and interfaces will be loaded automatically when they are needed. That's it!

With Composer

If you'd installed the component through Composer you can use the autoloader instance from Composer:

PHP
require 'vendor/autoload.php';

Error Handling

In SetaPDF 2 the error handling is done by throwing Exceptions throughout.

All SetaPDF exceptions are based on the SetaPDF_Exception class.

Furthermore the code will throw exceptions of following types: InvalidArgumentException, BadMethodCallException

So make sure that you catch at least the global Exception to keep control over the code flow:

PHP
try {
    ...
} catch (SetaPDF_Exception $e) {
    // SetaPDF specific error
} catch (Exception $e) {
    // global exception handling
}