Show
Ignore:
Timestamp:
03/07/08 08:33:04 (4 years ago)
Author:
nperriault
Message:

Clever Svg:

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

Warning: breaks BC from 0.5.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cleversvg/trunk/cleversvg.php

    r318 r336  
    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 
    192function __autoload($class) 
    203{ 
    21   $dirs = array('exceptions', 'base', 'gradients', 'elements', 'document'); 
     4  $dirs = array('exceptions', 
     5                'base', 
     6                'container', 
     7                'gradients', 
     8                'elements', 
     9                'importer', 
     10                'document', 
     11                'interfaces'); 
    2212  $pwd = dirname(__FILE__); 
    2313  foreach ($dirs as $dir) 
    2414  { 
    25     $class_file = sprintf('%s%s%s%s%s.class.php', 
    26                           $pwd, DIRECTORY_SEPARATOR, 
    27                           $dir, DIRECTORY_SEPARATOR, $class); 
    28     if (file_exists($class_file)) 
     15    foreach (array('class', 'interface') as $type) 
    2916    { 
    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      } 
    3132    } 
    3233  } 
    3334} 
     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');