apns-php
 All Data Structures Files Functions Variables Groups Pages
Autoload.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file
4  * Autoload stuff.
5  *
6  * LICENSE
7  *
8  * This source file is subject to the new BSD license that is bundled
9  * with this package in the file LICENSE.txt.
10  * It is also available through the world-wide-web at this URL:
11  * http://code.google.com/p/apns-php/wiki/License
12  * If you did not receive a copy of the license and are unable to
13  * obtain it through the world-wide-web, please send an email
14  * to aldo.armiento@gmail.com so we can send you a copy immediately.
15  *
16  * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com)
17  * @version $Id$
18  */
19 
20 /**
21  * This function is automatically called in case you are trying to use a
22  * class/interface which hasn't been defined yet. By calling this function the
23  * scripting engine is given a last chance to load the class before PHP
24  * fails with an error.
25  *
26  * @see http://php.net/__autoload
27  * @see http://php.net/spl_autoload_register
28  *
29  * @param $sClassName @type string The class name.
30  * @throws Exception if class name is empty, the current path is empty or class
31  * file does not exists or file was loaded but class name was not found.
32  */
33 function ApnsPHP_Autoload($sClassName)
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 }
58 spl_autoload_register('ApnsPHP_Autoload');
void ApnsPHP_Autoload(string $sClassName)
This function is automatically called in case you are trying to use a class/interface which hasn't be...
Definition: Autoload.php:33