コード例 #1
0
ファイル: iterator.class.php プロジェクト: jvirtism/AnEngine
 /**
  * Return current element
  *
  * Returns the current element value inside wrapper object
  *
  * Method for the {@link Iterator} interface implementation
  *
  * @return AeType current element or null, if array is empty
  */
 public function current()
 {
     if (!$this->valid()) {
         return null;
     }
     return $this->_array->offsetGet($this->_key);
 }
コード例 #2
0
ファイル: database.class.php プロジェクト: jvirtism/AnEngine
 /**
  * Get connection
  *
  * Returns a database connection. If the connection is not established, uses
  * options provided to establish one.
  *
  * @throws AeSessionDriverDatabaseException #400 if database options are
  *                                          invalid
  *
  * @return AeInterface_Database
  */
 public function getConnection()
 {
     if ($this->_connection instanceof AeInterface_Database && !$this->_connection->isConnected()) {
         // *** The connection is lost, try to reestablish it
         $this->_connection = null;
     }
     if (!$this->_connection instanceof AeInterface_Database) {
         // *** Establish connection first
         if ($this->_options instanceof AeArray) {
             // *** An array of settings
             if (isset($this->_options['name'])) {
                 // *** Connection name and settings file path assumed
                 $this->_connection = AeDatabase::getConnection($this->_options['name'], $this->_options['settings']);
             } else {
                 if (isset($this->_options['driver'])) {
                     // *** Connection options array assumed
                     $this->_connection = AeDatabase::getInstance($this->_options['driver'], $this->_options['username'], $this->_options['password'], $this->_options['options']->value);
                 } else {
                     // *** Invalid options array
                     throw new AeSessionDriverDatabaseException('Invalid database connection options', 400);
                 }
             }
         } else {
             if ($this->_options instanceof AeCallback) {
                 // *** A callback
                 $this->_connection = $this->_options->call();
                 if (!$this->_connection instanceof AeInterface_Database) {
                     // *** Invalid callback return value
                     throw new AeSessionDriverDatabaseException('Invalid database connection options', 400);
                 }
             } else {
                 // *** Invalid options value
                 throw new AeSessionDriverDatabaseException('Invalid database connection options', 400);
             }
         }
     }
     return $this->_connection;
 }
コード例 #3
0
ファイル: type.class.php プロジェクト: jvirtism/AnEngine
 /**
  * Wrap return
  *
  * This method wraps (or unwraps) the value passed according to all the
  * <var>$wrapReturn</var> settings.
  *
  * @param mixed $value
  * @param mixed $default
  *
  * @return mixed
  */
 public static function wrapReturn($value, $default = null)
 {
     if ($value instanceof AeType) {
         $value = $value->getValue() === null ? $default : $value;
     } else {
         $value = $value === null ? $default : $value;
     }
     if (self::of($value) != 'object') {
         // *** Wrap, if enabled
         if (self::$wrapReturn === true && !$value instanceof AeType) {
             return self::wrap($value);
         }
         // *** Detect further down the class tree
         if (self::$wrapReturn === null) {
             if (is_scalar($value) || $value instanceof AeScalar) {
                 return AeScalar::_wrapReturn($value);
             }
             if (is_array($value) || $value instanceof AeArray) {
                 return AeArray::_wrapReturn($value);
             }
         }
         // *** Unwrap if disabled
         if (self::$wrapReturn === false && $value instanceof AeType) {
             return $value->getValue();
         }
     }
     return $value;
 }