Add a couple helpers to the resource class
[gitphp.git] / include / Resource.class.php
blob:a/include/Resource.class.php -> blob:b/include/Resource.class.php
<?php <?php
/** /**
* GitPHP Resource * GitPHP Resource
* *
* Resource factory * Resource factory
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
*/ */
   
require_once(GITPHP_BASEDIR . 'lib/php-gettext/streams.php'); require_once(GITPHP_BASEDIR . 'lib/php-gettext/streams.php');
require_once(GITPHP_BASEDIR . 'lib/php-gettext/gettext.php'); require_once(GITPHP_BASEDIR . 'lib/php-gettext/gettext.php');
   
/** /**
* Resource * Resource
* *
* @package GitPHP * @package GitPHP
* @subpackage Resource * @subpackage Resource
*/ */
class GitPHP_Resource class GitPHP_Resource
{ {
/** /**
* instance * instance
* *
* Stores the singleton instance of the resource provider * Stores the singleton instance of the resource provider
* *
* @access protected * @access protected
* @static * @static
*/ */
protected static $instance = null; protected static $instance = null;
   
/** /**
  * currentLocale
  *
  * Stores the currently instantiated locale identifier
  *
  * @access protected
  * @static
  */
  protected static $currentLocale = '';
   
  /**
* GetInstance * GetInstance
* *
* Returns the singleton instance * Returns the singleton instance
* *
* @access public * @access public
* @static * @static
* @return mixed instance of resource class * @return mixed instance of resource class
* @throws Exception if resource provider has not been instantiated yet  
*/ */
public static function GetInstance() public static function GetInstance()
{ {
return self::$instance; return self::$instance;
  }
   
  /**
  * Instantiated
  *
  * Tests if the resource provider has been instantiated
  *
  * @access public
  * @static
  * @return boolean true if resource provider is instantiated
  */
  public static function Instantiated()
  {
  return (self::$instance !== null);
  }
   
  /**
  * GetLocale
  *
  * Gets the currently instantiated locale
  *
  * @access public
  * @static
  * @return string locale identifier
  */
  public static function GetLocale()
  {
  return self::$currentLocale;
} }
   
/** /**
* Instantiate * Instantiate
* *
* Instantiates the singleton instance * Instantiates the singleton instance
* *
* @access public * @access public
* @static * @static
* @param string $locale locale to instantiate * @param string $locale locale to instantiate
* @throws Exception on invalid locale * @return boolean true if resource provider was instantiated successfully
*/ */
public static function Instantiate($locale) public static function Instantiate($locale)
{ {
  self::$instance = null;
  self::$currentLocale = '';
   
$reader = null; $reader = null;
   
if (!(($locale == 'en_US') || ($locale == 'en'))) { if (!(($locale == 'en_US') || ($locale == 'en'))) {
$reader = new FileReader(GITPHP_LOCALEDIR . $locale . '/gitphp.mo'); $reader = new FileReader(GITPHP_LOCALEDIR . $locale . '/gitphp.mo');
  if (!$reader)
  return false;
} }
   
self::$instance = new gettext_reader($reader); self::$instance = new gettext_reader($reader);
  self::$currentLocale = $locale;
  return true;
} }
   
} }
   
comments