src/Context/PhonarcContext.php
/**
   * Generate the PhonarcContext object or return from cache.
   * @param string $context_id
   * @return PhonarcContext
   */
Generate the PhonarcContext object or return from cache.
Generate the PhonarcContext object or return from cache .
static public function factory($context_id = NULL) {
    static $contexts = array();
    static $prev = NULL;
    if (is_object($context_id)) {
      $contexts[$context_id->getId()] = $context_id;
      return $contexts[$context_id->getId()];
    }
    if (isset($context_id)) {
      if ($context_id == PhonarcContext::CURRENT_CONTEXT) {
        if (!isset($prev)) {
          $ids = array_keys($contexts);
          $prev = array_shift($ids);
        }
      }
      elseif ($context_id == PhonarcContext::NEXT_CONTEXT) {
        $ids = array_keys($contexts);
        if (!isset($prev)) {
          $prev = array_shift($ids);
        }
        else {
          $idix = array_search($prev, $ids);
          if ($idix == sizeof($ids) - 1) {
            $prev = NULL;
          }
          else {
            $prev = $ids[$idix + 1];
          }
        }
      }
      else {
        $prev = $context_id;
      }
    }
    if (!isset($prev) || !isset($contexts[$prev])) {
      return NULL;
    }
    return $contexts[$prev];
  }
static public function factory ( $ context_id = NULL ) { static $ contexts = array ( ) ; static $ prev = NULL ; if ( is_object ( $ context_id ) ) { $ contexts [ $ context_id -> getId ( ) ] = $ context_id ; return $ contexts [ $ context_id -> getId ( ) ] ; } if ( isset ( $ context_id ) ) { if ( $ context_id == PhonarcContext :: CURRENT_CONTEXT ) { if ( ! isset ( $ prev ) ) { $ ids = array_keys ( $ contexts ) ; $ prev = array_shift ( $ ids ) ; } } elseif ( $ context_id == PhonarcContext :: NEXT_CONTEXT ) { $ ids = array_keys ( $ contexts ) ; if ( ! isset ( $ prev ) ) { $ prev = array_shift ( $ ids ) ; } else { $ idix = array_search ( $ prev , $ ids ) ; if ( $ idix == sizeof ( $ ids ) - 1 ) { $ prev = NULL ; } else { $ prev = $ ids [ $ idix + 1 ] ; } } } else { $ prev = $ context_id ; } } if ( ! isset ( $ prev ) || ! isset ( $ contexts [ $ prev ] ) ) { return NULL ; } return $ contexts [ $ prev ] ; }
Generate the PhonarcContext object or return from cache.
Generate the PhonarcContext object or return from cache .
// Add another context to the factory. // Build any new requested context.