apns-php
 All Data Structures Files Functions Variables Groups Pages
Autoload.php File Reference

Autoload stuff. More...

Go to the source code of this file.

Functions

void ApnsPHP_Autoload (string $sClassName)
 This function is automatically called in case you are trying to use a class/interface which hasn't been defined yet. More...
 

Detailed Description

Autoload stuff.

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://code.google.com/p/apns-php/wiki/License If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to aldo..nosp@m.armi.nosp@m.ento@.nosp@m.gmai.nosp@m.l.com so we can send you a copy immediately.

Author
(C) 2010 Aldo Armiento (aldo..nosp@m.armi.nosp@m.ento@.nosp@m.gmai.nosp@m.l.com)
Version
$Id$

Definition in file Autoload.php.

Function Documentation

void ApnsPHP_Autoload ( string  $sClassName)

This function is automatically called in case you are trying to use a class/interface which hasn't been defined yet.

By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.

See Also
http://php.net/__autoload
http://php.net/spl_autoload_register
Parameters
$sClassNameThe class name.
Exceptions
Exceptionif class name is empty, the current path is empty or class file does not exists or file was loaded but class name was not found.

Definition at line 33 of file Autoload.php.

34 {
35  if (empty($sClassName)) {
36  throw new Exception('Class name is empty');
37  }
38 
39  $sPath = dirname(dirname(__FILE__));
40  if (empty($sPath)) {
41  throw new Exception('Current path is empty');
42  }
43 
44  $sFile = sprintf('%s%s%s.php',
45  $sPath, DIRECTORY_SEPARATOR,
46  str_replace('_', DIRECTORY_SEPARATOR, $sClassName)
47  );
48  if (is_file($sFile) && is_readable($sFile)) {
49  require_once $sFile;
50  }
51 }
52 
53 // If your code has an existing __autoload function then this function must be explicitly registered on the __autoload stack.
54 // (PHP Documentation for spl_autoload_register [@see http://php.net/spl_autoload_register])
55 if (function_exists('__autoload')) {
56  spl_autoload_register('__autoload');
57 }