Changeset 1084
- Timestamp:
- 11/11/2007 12:59:10 AM (11 months ago)
- Location:
- trunk/system
- Files:
-
- 4 modified
-
core/Event.php (modified) (1 diff)
-
core/Kohana.php (modified) (5 diffs)
-
libraries/Router.php (modified) (3 diffs)
-
libraries/View.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/core/Event.php
r933 r1084 70 70 public static function add($name, $callback) 71 71 { 72 if ($name == FALSE OR $callback == FALSE) 73 return FALSE; 74 75 // Make sure that the event name is defined 72 if (empty($name) OR empty($callback)) 73 return FALSE; 74 76 75 if ( ! isset(self::$events[$name])) 77 76 { 77 // Create an empty event if it is not yet defined 78 78 self::$events[$name] = array(); 79 79 } 80 80 81 // Make sure the event is not already in the queue82 81 if ( ! in_array($callback, self::$events[$name])) 83 82 { 83 // Add the event if it does not already exist in the queue 84 84 self::$events[$name][] = $callback; 85 85 } 86 } 87 88 /* 89 * Method: add_before 90 * Add a callback to an event queue, before a given event. 91 * 92 * Parameters: 93 * name - event name 94 * existing - existing event callback 95 * callback - event callback 96 */ 97 public static function add_before($name, $existing, $callback) 98 { 99 if (empty($name) OR empty($existing) OR empty($callback)) 100 return FALSE; 101 102 if ( ! isset(self::$events[$name]) OR ($key = array_search($existing, self::$events[$name])) === FALSE) 103 { 104 // Add the event if there are no events or if the exsisting event is not set 105 self::add($name, $callback); 106 } 107 else 108 { 109 // Insert the event immediately before the existing event 110 self::insert_event($name, $key, $callback); 111 } 112 113 return TRUE; 114 } 115 116 /* 117 * Method: add_after 118 * Add a callback to an event queue, after a given event. 119 * 120 * Parameters: 121 * name - event name 122 * existing - existing event callback 123 * callback - event callback 124 */ 125 public static function add_after($name, $existing, $callback) 126 { 127 if (empty($name) OR empty($existing) OR empty($callback)) 128 return FALSE; 129 130 if ( ! isset(self::$events[$name]) OR ($key = array_search($existing, self::$events[$name])) === FALSE) 131 { 132 // Add the event if there are no events or if the exsisting event is not set 133 self::add($name, $callback); 134 } 135 else 136 { 137 // Insert the event immediately after the existing event 138 self::insert_event($name, $key + 1, $callback); 139 } 140 141 return TRUE; 142 } 143 144 /* 145 * Method: insert_event 146 * Inserts a new event at a specfic key location. 147 * 148 * Parameters: 149 * name - event name 150 * key - key to insert new event at 151 * callback - event callback 152 */ 153 private static function insert_event($name, $key, $callback) 154 { 155 // Add the new event at the given key location 156 self::$events[$name] = array_merge 157 ( 158 // Events before the key 159 array_slice(self::$events[$name], 0, $key), 160 // New event callback 161 array($callback), 162 // Events after the key 163 array_slice(self::$events[$name], $key) 164 ); 86 165 } 87 166 -
trunk/system/core/Kohana.php
r1047 r1084 118 118 setlocale(LC_ALL, Config::item('locale.language').'.UTF-8'); 119 119 120 // Enable Kohana routing 121 Event::add('system.routing', array('Router', 'find_uri')); 122 Event::add('system.routing', array('Router', 'setup')); 123 124 // Enable Kohana controller initialization 125 Event::add('system.execute', array('Kohana', 'instance')); 126 127 // Enable Kohana output handling 128 Event::add('system.shutdown', array('Kohana', 'display')); 129 120 130 if ($hooks = Config::item('hooks.enable')) 121 131 { 122 // All hooks are enabled, we must build an array of filenames123 132 if ( ! is_array($hooks)) 124 133 { 125 $hooks = array(); 126 foreach(Config::include_paths() as $path) 127 { 128 // Find all the hooks in each path 129 if ($files = glob($path.'hooks/*'.EXT)) 130 { 131 $hooks = array_merge($hooks, $files); 132 } 133 } 134 // All hooks are enabled, find them 135 $hooks = Kohana::list_files('hooks'); 134 136 } 135 137 … … 143 145 } 144 146 } 145 146 // Enable Kohana routing147 Event::add('system.routing', array('Router', 'setup'));148 149 // Enable Kohana controller initialization150 Event::add('system.execute', array('Kohana', 'instance'));151 152 // Enable Kohana output handling153 Event::add('system.shutdown', array('Kohana', 'display'));154 147 155 148 if (Config::item('log.threshold') > 0) … … 491 484 } 492 485 493 require self::find_file($type, $file, TRUE);486 require_once self::find_file($type, $file, TRUE); 494 487 495 488 if ($type == 'libraries') … … 499 492 require $extension; 500 493 } 501 else 494 elseif (substr($class, -5) !== '_Core') 502 495 { 503 496 eval('class '.$class.' extends '.$class.'_Core { }'); … … 686 679 { 687 680 // No array to search 688 if ( empty($keys) OR empty($array))681 if ((empty($keys) AND is_array($keys)) OR (empty($array) AND is_array($array))) 689 682 return; 690 683 -
trunk/system/libraries/Router.php
r932 r1084 35 35 throw new Kohana_Exception('core.no_default_route'); 36 36 37 // The follow block of if/else attempts to retrieve the URI segments automagically38 // Supported methods: CLI, GET, PATH_INFO, ORIG_PATH_INFO, PHP_SELF39 if (PHP_SAPI === 'cli')40 {41 // Command line requires a bit of hacking42 if (isset($_SERVER['argv'][1]))43 {44 self::$segments = $_SERVER['argv'][1];45 46 // Remove GET string from segments47 if (($query = strrpos(self::$segments, '?')) !== FALSE)48 {49 list (self::$segments, $query) = explode('?', self::$segments);50 51 // Insert query into GET array52 foreach(explode('&', $query) as $pair)53 {54 list ($key, $val) = array_pad(explode('=', $pair), 1, '');55 56 $_GET[utf8::clean($key)] = utf8::clean($val);57 }58 }59 }60 }61 elseif (count($_GET) === 1 AND current($_GET) == '')62 {63 self::$segments = current(array_keys($_GET));64 65 // Fixes really stange handling of a suffix in a GET string66 if ($suffix = Config::item('core.url_suffix') AND substr(self::$segments, -(strlen($suffix))) === '_'.substr($suffix, 1))67 {68 self::$segments = substr(self::$segments, 0, -(strlen($suffix)));69 }70 71 // Destroy GET72 $_GET = array();73 }74 elseif (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO'])75 {76 self::$segments = $_SERVER['PATH_INFO'];77 }78 elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO'])79 {80 self::$segments = $_SERVER['ORIG_PATH_INFO'];81 }82 elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF'])83 {84 self::$segments = $_SERVER['PHP_SELF'];85 }86 87 // Find the URI string based on the location of the front controller88 if (($offset = strpos(self::$segments, KOHANA)) !== FALSE)89 {90 // Add the length of the index file to the offset91 $offset += strlen(KOHANA);92 93 // Get the segment part of the URL94 self::$segments = substr(self::$segments, $offset);95 self::$segments = trim(self::$segments, '/');96 }97 98 99 37 // Use the default route when no segments exist 100 if (self::$ segments == '' OR self::$segments== '/')101 { 102 self::$ segments= self::$routes['_default'];38 if (self::$current_uri == '' OR self::$current_uri == '/') 39 { 40 self::$current_uri = self::$routes['_default']; 103 41 $default_route = TRUE; 104 42 } … … 111 49 if ($suffix = Config::item('core.url_suffix')) 112 50 { 113 self::$ segments = preg_replace('!'.preg_quote($suffix).'$!u', '', self::$segments);51 self::$current_uri = preg_replace('!'.preg_quote($suffix).'$!u', '', self::$current_uri); 114 52 } 115 53 116 54 // Remove extra slashes from the segments that could cause fucked up routing 117 self::$ segments = preg_replace('!//+!', '/', self::$segments);55 self::$current_uri = preg_replace('!//+!', '/', self::$current_uri); 118 56 119 57 // At this point, set the segments, rsegments, and current URI 120 58 // In many cases, all of these variables will match 121 self::$segments = self::$rsegments = self::$current_uri = trim(self::$ segments, '/');59 self::$segments = self::$rsegments = self::$current_uri = trim(self::$current_uri, '/'); 122 60 123 61 (self::$segments === 'L0LEAST3R') and include SYSPATH.'views/kohana_holiday.php'; … … 243 181 { 244 182 Kohana::show_404(); 183 } 184 } 185 186 /* 187 * Method: find_uri 188 * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. 189 */ 190 public static function find_uri() 191 { 192 if (PHP_SAPI === 'cli') 193 { 194 // Command line requires a bit of hacking 195 if (isset($_SERVER['argv'][1])) 196 { 197 self::$current_uri = $_SERVER['argv'][1]; 198 199 // Remove GET string from segments 200 if (($query = strpos(self::$current_uri, '?')) !== FALSE) 201 { 202 list (self::$current_uri, $query) = explode('?', self::$segments, 2); 203 204 // Insert query into GET array 205 foreach(explode('&', $query) as $pair) 206 { 207 list ($key, $val) = array_pad(explode('=', $pair), 1, ''); 208 209 $_GET[utf8::clean($key)] = utf8::clean($val); 210 } 211 } 212 } 213 } 214 elseif (count($_GET) === 1 AND current($_GET) == '') 215 { 216 self::$current_uri = current(array_keys($_GET)); 217 218 // Fixes really stange handling of a suffix in a GET string 219 if ($suffix = Config::item('core.url_suffix') AND substr(self::$current_uri, -(strlen($suffix))) === '_'.substr($suffix, 1)) 220 { 221 self::$current_uri = substr(self::$current_uri, 0, -(strlen($suffix))); 222 } 223 224 // Destroy GET 225 $_GET = array(); 226 } 227 elseif (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO']) 228 { 229 self::$current_uri = $_SERVER['PATH_INFO']; 230 } 231 elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) 232 { 233 self::$current_uri = $_SERVER['ORIG_PATH_INFO']; 234 } 235 elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) 236 { 237 self::$current_uri = $_SERVER['PHP_SELF']; 238 } 239 240 // Find the URI string based on the location of the front controller 241 if (($offset = strpos(self::$current_uri, KOHANA)) !== FALSE) 242 { 243 // Add the length of the index file to the offset 244 $offset += strlen(KOHANA); 245 246 // Get the segment part of the URL 247 self::$current_uri = substr(self::$current_uri, $offset); 248 self::$current_uri = trim(self::$current_uri, '/'); 245 249 } 246 250 } -
trunk/system/libraries/View.php
r1016 r1084 45 45 if (is_array($data) AND ! empty($data)) 46 46 { 47 foreach($data as $name => $value) 48 { 49 $this->data[$name] = $value; 50 } 47 $this->data = $data; 51 48 } 52 49 … … 65 62 * View object 66 63 */ 67 public function set($name, $value )64 public function set($name, $value = NULL) 68 65 { 69 $this->__set($name, $value); 66 if (func_num_args() === 1 AND is_array($name)) 67 { 68 foreach($name as $key => $value) 69 { 70 $this->__set($key, $value); 71 } 72 } 73 else 74 { 75 $this->__set($name, $value); 76 } 70 77 return $this; 71 78 }
