root/cleversvg/trunk/cleversvg.php

Revision 336, 1.7 KB (checked in by nperriault, 4 years ago)

Clever Svg:

  • refs #40: more elements tests
  • Removed depth management, as svg handle it natively

Warning: breaks BC from 0.5.

Line 
1<?php // CleverSvg framework class autoloading
2function __autoload($class)
3{
4  $dirs = array('exceptions',
5                'base',
6                'container',
7                'gradients',
8                'elements',
9                'importer',
10                'document',
11                'interfaces');
12  $pwd = dirname(__FILE__);
13  foreach ($dirs as $dir)
14  {
15    foreach (array('class', 'interface') as $type)
16    {
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      }
32    }
33  }
34}
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 */
47function 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}
72set_error_handler('cs_error_handler');
Note: See TracBrowser for help on using the browser.