sfContext::hasInstance PHP Method

hasInstance() public static method

Checks to see if there has been a context created
public static hasInstance ( string $name = null ) : boolean
$name string The name of the sfContext to check for
return boolean true is instanced, otherwise false
    public static function hasInstance($name = null)
    {
        if (null === $name) {
            $name = self::$current;
        }
        return isset(self::$instances[$name]);
    }

Usage Example

 /**
  * Create all TCPDF specific constants.
  *
  * @author COil
  * @since  V1.6.0 - 7 apr 09
  *
  * @return Array
  */
 public static function applyTCPDFConfig($config)
 {
     foreach ($config as $key => $value) {
         switch ($key) {
             case 'K_TCPDF_EXTERNAL_CONFIG':
                 if ($value) {
                     define('K_TCPDF_EXTERNAL_CONFIG', true);
                 }
                 break;
             case 'K_PATH_MAIN':
                 if (empty($value)) {
                     $value = sfConfig::get('sfTCPDFPlugin_dir');
                 }
                 define('K_PATH_MAIN', $value);
                 break;
             case 'K_PATH_URL':
                 if (empty($value) && sfContext::hasInstance()) {
                     $value = sfContext::getInstance()->getRequest()->getUriPrefix() . '/';
                 }
                 define('K_PATH_URL', $value);
                 break;
             case 'K_PATH_FONTS':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'fonts/';
                 }
                 define('K_PATH_FONTS', $value);
                 break;
             case 'K_PATH_CACHE':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'cache/';
                 }
                 define('K_PATH_CACHE', $value);
                 break;
             case 'K_PATH_URL_CACHE':
                 if (empty($value)) {
                     $value = K_PATH_URL . 'cache/';
                 }
                 define('K_PATH_URL_CACHE', $value);
                 break;
             case 'K_PATH_IMAGES':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'images/';
                 }
                 define('K_PATH_IMAGES', $value);
                 break;
             case 'K_BLANK_IMAGE':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'images/';
                 }
                 define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png');
                 break;
             default:
                 // Only define a constant if it's a known TCPDF constant
                 if (in_array($key, self::getTCPDFConstantsList())) {
                     define($key, $value);
                 }
                 break;
         }
     }
 }
All Usage Examples Of sfContext::hasInstance