| [ Index ] |
PHP Cross Reference of JPSpan 0.4 (beta) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Swiped from WACT: http://wact.sourceforge.net (handle.inc.php) 4 * @package JPSpan 5 * @subpackage Handle 6 * @see http://wact.sourceforge.net/index.php/ResolveHandle 7 * @version $Id: Handle.php,v 1.1 2004/11/09 13:30:39 harryf Exp $ 8 */ 9 //----------------------------------------------------------------------------- 10 11 /** 12 * Contains static methods for resolving and reflecting on handles 13 * @see http://wact.sourceforge.net/index.php/Handle 14 * @package JPSpan 15 * @subpackage Handle 16 */ 17 class JPSpan_Handle { 18 19 /** 20 * Takes a "handle" to an object and modifies it to convert it to an instance 21 * of the class. Allows for "lazy loading" of objects on demand. 22 * @see http://wact.sourceforge.net/index.php/ResolveHandle 23 * @todo Cases where Handle not array, string or object? 24 * @param mixed 25 * @return boolean FALSE if handle not resolved 26 * @access public 27 * @static 28 */ 29 function resolve(&$Handle) { 30 31 switch ( gettype($Handle) ) { 32 case 'array': 33 $Class = array_shift($Handle); 34 $ConstructionArgs = $Handle; 35 break; 36 case 'string': 37 $ConstructionArgs = array(); 38 $Class = $Handle; 39 break; 40 case 'object': 41 return TRUE; 42 break; 43 default: 44 return FALSE; 45 break; 46 } 47 48 if (is_integer($Pos = strpos($Class, '|'))) { 49 $File = substr($Class, 0, $Pos); 50 $Class = substr($Class, $Pos + 1); 51 require_once $File; 52 } 53 54 switch (count($ConstructionArgs)) { 55 case 0: 56 $Handle = new $Class(); 57 break; 58 case 1: 59 $Handle = new $Class(array_shift($ConstructionArgs)); 60 break; 61 case 2: 62 $Handle = new $Class( 63 array_shift($ConstructionArgs), 64 array_shift($ConstructionArgs)); 65 break; 66 case 3: 67 $Handle = new $Class( 68 array_shift($ConstructionArgs), 69 array_shift($ConstructionArgs), 70 array_shift($ConstructionArgs)); 71 break; 72 default: 73 trigger_error( 74 'Maximum constructor arg count exceeded', 75 E_USER_ERROR 76 ); 77 return FALSE; 78 break; 79 } 80 return TRUE; 81 } 82 83 /** 84 * Determines the "public" class methods exposed by a handle 85 * Class constructors and methods beginning with an underscore 86 * are ignored. 87 * @see http://wact.sourceforge.net/index.php/ResolveHandle 88 * @todo Cases where Handle not array, string or object? 89 * @param mixed 90 * @return mixed JPSpan_HandleDescription or FALSE if invalid handle 91 * @access public 92 * @static 93 */ 94 function examine($Handle) { 95 96 switch ( gettype($Handle) ) { 97 case 'array': 98 $Class = array_shift($Handle); 99 break; 100 case 'string': 101 $Class = $Handle; 102 break; 103 case 'object': 104 $Class = get_class($Handle); 105 break; 106 default: 107 return FALSE; 108 break; 109 } 110 111 if (is_integer($Pos = strpos($Class, '|'))) { 112 $File = substr($Class, 0, $Pos); 113 $Class = substr($Class, $Pos + 1); 114 require_once $File; 115 } 116 117 $Class = strtolower($Class); 118 119 $Description = new JPSpan_HandleDescription(); 120 $Description->Class = $Class; 121 122 $methods = get_class_methods($Class); 123 if ( is_null($methods) ) { 124 return FALSE; 125 } 126 $methods = array_map('strtolower',$methods); 127 128 if ( FALSE !== ( $constructor = array_search($Class,$methods) ) ) { 129 unset($methods[$constructor]); 130 } 131 132 foreach ( $methods as $method ) { 133 if ( preg_match('/^[a-z]+[0-9a-z_]*$/',$method) == 1 ) { 134 $Description->methods[] = $method; 135 } 136 } 137 138 return $Description; 139 } 140 141 } 142 //----------------------------------------------------------------------------- 143 144 /** 145 * Describes a handle: used to help generate Javascript clients 146 * and validate incoming calls 147 * @package JPSpan 148 * @subpackage Handle 149 */ 150 class JPSpan_HandleDescription { 151 152 /** 153 * @var string class name for handle 154 * @access public 155 */ 156 var $Class = ''; 157 158 /** 159 * @var array methods exposed by handle 160 * @access public 161 */ 162 var $methods = array(); 163 164 } 165 166
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Nov 26 11:42:46 2004 | Cross-referenced by PHPXref 0.6 |