| 1 | | <?php |
| 2 | | /** |
| 3 | | * CleverSvg library |
| 4 | | * Include this file to be able to use the library, eg. : |
| 5 | | * <pre> |
| 6 | | * require_once('cleversvg.php'); |
| 7 | | * $doc = new csDocument(550, 400, 'Untitled Document'); |
| 8 | | * $rect = new csRect(10, 10, 100, 100); |
| 9 | | * $rect->setFill('red'); |
| 10 | | * $doc->addElement($rect); |
| 11 | | * header("content-type: image/svg+xml; charset=utf-8"); |
| 12 | | * echo $doc->toXML(); |
| 13 | | * </pre> |
| 14 | | * |
| 15 | | * @author Nicolas Perriault <nperriault@gmail.com> |
| 16 | | * @package cleversvg |
| 17 | | */ |
| 18 | | |
| | 1 | <?php // CleverSvg framework class autoloading |
| 30 | | class_exists($class) or require($class_file); |
| | 17 | $class_file = sprintf('%s%s%s%s%s.%s.php', |
| | 18 | $pwd, DIRECTORY_SEPARATOR, |
| | 19 | $dir, DIRECTORY_SEPARATOR, $class, |
| | 20 | $type); |
| | 21 | if (file_exists($class_file)) |
| | 22 | { |
| | 23 | if ($type == 'interface') |
| | 24 | { |
| | 25 | interface_exists($class) or require($class_file); |
| | 26 | } |
| | 27 | else |
| | 28 | { |
| | 29 | class_exists($class) or require($class_file); |
| | 30 | } |
| | 31 | } |
| | 35 | |
| | 36 | /** |
| | 37 | * CleverSvg default PHP error handler |
| | 38 | * |
| | 39 | * TODO: switch from error code to provide specific errors |
| | 40 | * |
| | 41 | * @param int $code |
| | 42 | * @param string $message |
| | 43 | * @param string $file |
| | 44 | * @param int $line |
| | 45 | * @throws csException |
| | 46 | */ |
| | 47 | function cs_error_handler($code, $message, $file, $line) |
| | 48 | { |
| | 49 | switch ($code) |
| | 50 | { |
| | 51 | case E_USER_ERROR: |
| | 52 | $type = 'Error'; |
| | 53 | $exception = 'csException'; |
| | 54 | break; |
| | 55 | case E_USER_WARNING: |
| | 56 | $type = 'Warning'; |
| | 57 | $exception = 'csException'; |
| | 58 | break; |
| | 59 | case E_USER_NOTICE: |
| | 60 | $type = 'Notice'; |
| | 61 | $exception = 'csException'; |
| | 62 | break; |
| | 63 | default: |
| | 64 | $type = 'Unknown error'; |
| | 65 | $exception = 'csException'; |
| | 66 | break; |
| | 67 | } |
| | 68 | $message = sprintf('%s "%s" in %s line %d', |
| | 69 | $type, $message, $file, $line); |
| | 70 | throw new $exception($message, $code); |
| | 71 | } |
| | 72 | set_error_handler('cs_error_handler'); |