[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/balanced-php/src/Balanced/ -> Bootstrap.php (source)

   1  <?php
   2  
   3  namespace Balanced;
   4  
   5  /**
   6   * Bootstrapper for Balanced does autoloading and resource initialization.
   7   */
   8  class Bootstrap
   9  {
  10      const DIR_SEPARATOR = DIRECTORY_SEPARATOR;
  11      const NAMESPACE_SEPARATOR = '\\';
  12  
  13      public static $initialized = false;
  14      
  15      
  16      public static function init()
  17      {
  18          spl_autoload_register(array('\Balanced\Bootstrap', 'autoload'));
  19          self::initializeResources();
  20      }
  21      
  22      public static function autoload($classname)
  23      {
  24          self::_autoload(dirname(dirname(__FILE__)), $classname);
  25      }
  26      
  27      public static function pharInit()
  28      {
  29          spl_autoload_register(array('\Balanced\Bootstrap', 'pharAutoload'));
  30          self::initializeResources();
  31      }
  32      
  33      public static function pharAutoload($classname)
  34      {
  35          self::_autoload('phar://balanced.phar', $classname);
  36      }
  37      
  38      private static function _autoload($base, $classname)
  39      {
  40          if (!strncmp($classname, 'Balanced\Errors\\', strlen('Balanced\Errors\\')))
  41              $classname = 'Balanced\Errors';
  42          $parts = explode(self::NAMESPACE_SEPARATOR, $classname);
  43          $path = $base . self::DIR_SEPARATOR. implode(self::DIR_SEPARATOR, $parts) . '.php';
  44          if (file_exists($path)) {
  45              require_once($path);
  46          }
  47      }
  48  
  49      /**
  50       * Initializes resources (i.e. registers them with Resource::_registry). Note
  51       * that if you add a Resource then you must initialize it here.
  52       * 
  53       * @internal
  54       */
  55      private static function initializeResources()
  56      {
  57          if (self::$initialized)
  58              return;
  59           
  60          \Balanced\Errors\Error::init();
  61  
  62          \Balanced\Resource::init();
  63  
  64          \Balanced\APIKey::init();
  65          \Balanced\Marketplace::init();
  66          \Balanced\Account::init();
  67          \Balanced\Credit::init();
  68          \Balanced\Debit::init();
  69          \Balanced\Refund::init();
  70          \Balanced\Card::init();
  71          \Balanced\BankAccount::init();
  72          \Balanced\Hold::init();
  73          \Balanced\Merchant::init();
  74          \Balanced\Callback::init();
  75          \Balanced\Event::init();
  76  
  77          self::$initialized = true;
  78      }
  79  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1