Hoa central
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
Hoa\Core\Protocol\Wrapper Class Reference

Public Member Functions

 stream_cast ($castAs)
 
 stream_close ()
 
 stream_eof ()
 
 stream_flush ()
 
 stream_lock ($operation)
 
 stream_metadata ($path, $option, $values)
 
 stream_open ($path, $mode, $options, &$openedPath)
 
 stream_read ($count)
 
 stream_seek ($offset, $whence=SEEK_SET)
 
 stream_stat ()
 
 stream_tell ()
 
 stream_truncate ($size)
 
 stream_write ($data)
 
 dir_closedir ()
 
 dir_opendir ($path, $options)
 
 dir_readdir ()
 
 dir_rewinddir ()
 
 mkdir ($path, $mode, $options)
 
 rename ($from, $to)
 
 rmdir ($path, $options)
 
 unlink ($path)
 
 url_stat ($path, $flags)
 

Static Public Member Functions

static realPath ($path, $exists=true)
 

Public Attributes

 $context = null
 

Protected Member Functions

 getStream ()
 
 getStreamName ()
 

Private Attributes

 $_stream = null
 
 $_streamName = null
 

Detailed Description

Class .

Wrapper for hoa://'s protocol.

Definition at line 578 of file Protocol.php.

Member Function Documentation

Hoa\Core\Protocol\Wrapper::dir_closedir ( )

Close directory handle. This method is called in to closedir(). Any resources which were locked, or allocated, during opening and use of the directory stream should be released.

Returns
bool

Definition at line 892 of file Protocol.php.

893  {
894  if (true === $handle = @closedir($this->getStream())) {
895  $this->_stream = null;
896  $this->_streamName = null;
897  }
898 
899  return $handle;
900  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::dir_opendir (   $path,
  $options 
)

Open directory handle. This method is called in response to opendir().

Parameters
string$pathSpecifies the URL that was passed to opendir().
int$optionsWhether or not to enforce safe_mode (0x04). It is not used here.
Returns
bool

Definition at line 911 of file Protocol.php.

912  {
913  $path = static::realPath($path);
914  $handle = null;
915 
916  if (null === $this->context) {
917  $handle = @opendir($path);
918  } else {
919  $handle = @opendir($path, $this->context);
920  }
921 
922  if (false === $handle) {
923  return false;
924  }
925 
926  $this->_stream = $handle;
927  $this->_streamName = $path;
928 
929  return true;
930  }
Hoa\Core\Protocol\Wrapper::dir_readdir ( )

Read entry from directory handle. This method is called in response to readdir().

Returns
mixed

Definition at line 938 of file Protocol.php.

939  {
940  return readdir($this->getStream());
941  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::dir_rewinddir ( )

Rewind directory handle. This method is called in response to rewinddir(). Should reset the output generated by self::dir_readdir, i.e. the next call to self::dir_readdir should return the first entry in the location returned by self::dir_opendir.

Returns
bool

Definition at line 952 of file Protocol.php.

953  {
954  return rewinddir($this->getStream());
955  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::getStream ( )
protected

Get stream resource.

Returns
resource

Definition at line 1091 of file Protocol.php.

1092  {
1093  return $this->_stream;
1094  }

Here is the caller graph for this function:

Hoa\Core\Protocol\Wrapper::getStreamName ( )
protected

Get stream name.

Returns
resource

Definition at line 1101 of file Protocol.php.

1102  {
1103  return $this->_streamName;
1104  }
1105 }
1106 
1107 }
1108 
1109 namespace {
1110 
1121 if (!function_exists('resolve')) {
1122  function resolve($path, $exists = true, $unfold = false)
1123  {
1124  return Hoa\Core::getInstance()->getProtocol()->resolve(
1125  $path,
1126  $exists,
1127  $unfold
1128  );
1129  }
1130 }
static getInstance()
Definition: Core.php:193
Hoa\Core\Protocol\Wrapper::mkdir (   $path,
  $mode,
  $options 
)

Create a directory. This method is called in response to mkdir().

Parameters
string$pathDirectory which should be created.
int$modeThe value passed to mkdir().
int$optionsA bitwise mask of values.
Returns
bool

Definition at line 966 of file Protocol.php.

967  {
968  if (null === $this->context) {
969  return mkdir(
970  static::realPath($path, false),
971  $mode,
972  $options | STREAM_MKDIR_RECURSIVE
973  );
974  }
975 
976  return mkdir(
977  static::realPath($path, false),
978  $mode,
979  $options | STREAM_MKDIR_RECURSIVE,
980  $this->context
981  );
982  }
mkdir($path, $mode, $options)
Definition: Protocol.php:966
static Hoa\Core\Protocol\Wrapper::realPath (   $path,
  $exists = true 
)
static

Get the real path of the given URL. Could return false if the path cannot be reached.

Parameters
string$pathPath (or URL).
bool$existsIf true, try to find the first that exists,
Returns
mixed

Definition at line 611 of file Protocol.php.

612  {
613  return Core::getProtocol()->resolve($path, $exists);
614  }
static getProtocol()
Definition: Core.php:352

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::rename (   $from,
  $to 
)

Rename a file or directory. This method is called in response to rename(). Should attempt to rename $from to $to.

Parameters
string$fromThe URL to current file.
string$toThe URL which $from should be renamed to.
Returns
bool

Definition at line 993 of file Protocol.php.

994  {
995  if (null === $this->context) {
996  return rename(static::realPath($from), static::realPath($to, false));
997  }
998 
999  return rename(
1000  static::realPath($from),
1001  static::realPath($to, false),
1002  $this->context
1003  );
1004  }
Hoa\Core\Protocol\Wrapper::rmdir (   $path,
  $options 
)

Remove a directory. This method is called in response to rmdir().

Parameters
string$pathThe directory URL which should be removed.
int$optionsA bitwise mask of values. It is not used here.
Returns
bool

Definition at line 1015 of file Protocol.php.

1016  {
1017  if (null === $this->context) {
1018  return rmdir(static::realPath($path));
1019  }
1020 
1021  return rmdir(static::realPath($path), $this->context);
1022  }
rmdir($path, $options)
Definition: Protocol.php:1015
Hoa\Core\Protocol\Wrapper::stream_cast (   $castAs)

Retrieve the underlaying resource.

Parameters
int$castAsCan be STREAM_CAST_FOR_SELECT when stream_select() is calling stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for other uses.
Returns
resource

Definition at line 625 of file Protocol.php.

626  {
627  return false;
628  }
Hoa\Core\Protocol\Wrapper::stream_close ( )

Close a resource. This method is called in response to fclose(). All resources that were locked, or allocated, by the wrapper should be released.

Returns
void

Definition at line 638 of file Protocol.php.

639  {
640  if (true === @fclose($this->getStream())) {
641  $this->_stream = null;
642  $this->_streamName = null;
643  }
644 
645  return;
646  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_eof ( )

Tests for end-of-file on a file pointer. This method is called in response to feof().

access public

Returns
bool

Definition at line 655 of file Protocol.php.

656  {
657  return feof($this->getStream());
658  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_flush ( )

Flush the output. This method is called in respond to fflush(). If we have cached data in our stream but not yet stored it into the underlying storage, we should do so now.

Returns
bool

Definition at line 668 of file Protocol.php.

669  {
670  return fflush($this->getStream());
671  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_lock (   $operation)

Advisory file locking. This method is called in response to flock(), when file_put_contents() (when flags contains LOCK_EX), stream_set_blocking() and when closing the stream (LOCK_UN).

Parameters
int$operationOperation is one the following:
  • LOCK_SH to acquire a shared lock (reader) ;
  • LOCK_EX to acquire an exclusive lock (writer) ;
  • LOCK_UN to release a lock (shared or exclusive) ;
  • LOCK_NB if we don't want flock() to block while locking (not supported on Windows).
Returns
bool

Definition at line 688 of file Protocol.php.

689  {
690  return flock($this->getStream(), $operation);
691  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_metadata (   $path,
  $option,
  $values 
)

Change stream options. This method is called to set metadata on the stream. It is called when one of the following functions is called on a stream URL: touch, chmod, chown or chgrp.

Parameters
string$pathThe file path or URL to set metadata.
int$optionOne of the following constant:
  • STREAM_META_TOUCH,
  • STREAM_META_OWNER_NAME,
  • STREAM_META_OWNER,
  • STREAM_META_GROUP_NAME,
  • STREAM_META_GROUP,
  • STREAM_META_ACCESS.
mixed$valuesArguments of touch, chmod, chown and chgrp.
Returns
bool

Definition at line 710 of file Protocol.php.

711  {
712  $path = static::realPath($path, false);
713 
714  switch ($option) {
715  case STREAM_META_TOUCH:
716  $arity = count($values);
717 
718  if (0 === $arity) {
719  $out = touch($path);
720  } elseif (1 === $arity) {
721  $out = touch($path, $values[0]);
722  } else {
723  $out = touch($path, $values[0], $values[1]);
724  }
725 
726  break;
727 
728  case STREAM_META_OWNER_NAME:
729  case STREAM_META_OWNER:
730  $out = chown($path, $values);
731 
732  break;
733 
734  case STREAM_META_GROUP_NAME:
735  case STREAM_META_GROUP:
736  $out = chgrp($path, $values);
737 
738  break;
739 
740  case STREAM_META_ACCESS:
741  $out = chmod($path, $values);
742 
743  break;
744  }
745 
746  return $out;
747  }
Hoa\Core\Protocol\Wrapper::stream_open (   $path,
  $mode,
  $options,
$openedPath 
)

Open file or URL. This method is called immediately after the wrapper is initialized (f.e. by fopen() and file_get_contents()).

Parameters
string$pathSpecifies the URL that was passed to the original function.
string$modeThe mode used to open the file, as detailed for fopen().
int$optionsHolds additional flags set by the streams API. It can hold one or more of the following values OR'd together:
  • STREAM_USE_PATH, if path is relative, search for the resource using the include_path;
  • STREAM_REPORT_ERRORS, if this is set, you are responsible for raising errors using trigger_error during opening the stream. If this is not set, you should not raise any errors.
string&$openedPathIf the $path is opened successfully, and STREAM_USE_PATH is set in $options, $openedPath should be set to the full path of the file/resource that was actually opened.
Returns
bool

Definition at line 776 of file Protocol.php.

777  {
778  $path = static::realPath($path, 'r' === $mode[0]);
779 
780  if (Protocol::NO_RESOLUTION === $path) {
781  return false;
782  }
783 
784  if (null === $this->context) {
785  $openedPath = fopen($path, $mode, $options & STREAM_USE_PATH);
786  } else {
787  $openedPath = fopen(
788  $path,
789  $mode,
790  $options & STREAM_USE_PATH,
791  $this->context
792  );
793  }
794 
795  if (false === is_resource($openedPath)) {
796  return false;
797  }
798 
799  $this->_stream = $openedPath;
800  $this->_streamName = $path;
801 
802  return true;
803  }
Hoa\Core\Protocol\Wrapper::stream_read (   $count)

Read from stream. This method is called in response to fread() and fgets().

Parameters
int$countHow many bytes of data from the current position should be returned.
Returns
string

Definition at line 813 of file Protocol.php.

814  {
815  return fread($this->getStream(), $count);
816  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_seek (   $offset,
  $whence = SEEK_SET 
)

Seek to specific location in a stream. This method is called in response to fseek(). The read/write position of the stream should be updated according to the $offset and $whence.

Parameters
int$offsetThe stream offset to seek to.
int$whencePossible values:
  • SEEK_SET to set position equal to $offset bytes ;
  • SEEK_CUR to set position to current location plus $offsete ;
  • SEEK_END to set position to end-of-file plus $offset.
Returns
bool

Definition at line 834 of file Protocol.php.

835  {
836  return 0 === fseek($this->getStream(), $offset, $whence);
837  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_stat ( )

Retrieve information about a file resource. This method is called in response to fstat().

Returns
array

Definition at line 845 of file Protocol.php.

846  {
847  return fstat($this->getStream());
848  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_tell ( )

Retrieve the current position of a stream. This method is called in response to ftell().

Returns
int

Definition at line 856 of file Protocol.php.

857  {
858  return ftell($this->getStream());
859  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_truncate (   $size)

Truncate a stream to a given length.

Parameters
int$sizeSize.
Returns
bool

Definition at line 867 of file Protocol.php.

868  {
869  return ftruncate($this->getStream(), $size);
870  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::stream_write (   $data)

Write to stream. This method is called in response to fwrite().

Parameters
string$dataShould be stored into the underlying stream.
Returns
int

Definition at line 879 of file Protocol.php.

880  {
881  return fwrite($this->getStream(), $data);
882  }

Here is the call graph for this function:

Hoa\Core\Protocol\Wrapper::unlink (   $path)

Delete a file. This method is called in response to unlink().

Parameters
string$pathThe file URL which should be deleted.
Returns
bool

Definition at line 1031 of file Protocol.php.

1032  {
1033  if (null === $this->context) {
1034  return unlink(static::realPath($path));
1035  }
1036 
1037  return unlink(static::realPath($path), $this->context);
1038  }
Hoa\Core\Protocol\Wrapper::url_stat (   $path,
  $flags 
)

Retrieve information about a file. This method is called in response to all stat() related functions.

Parameters
string$pathThe file URL which should be retrieve information about.
int$flagsHolds additional flags set by the streams API. It can hold one or more of the following values OR'd together. STREAM_URL_STAT_LINK: for resource with the ability to link to other resource (such as an HTTP location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to lstat(), is_link(), or filetype(). STREAM_URL_STAT_QUIET: if this flag is set, our wrapper should not raise any errors. If this flag is not set, we are responsible for reporting errors using the trigger_error() function during stating of the path.
Returns
array

Definition at line 1064 of file Protocol.php.

1065  {
1066  $path = static::realPath($path);
1067 
1068  if (Protocol::NO_RESOLUTION === $path) {
1069  if ($flags & STREAM_URL_STAT_QUIET) {
1070  return 0;
1071  } else {
1072  return trigger_error(
1073  'Path ' . $path . ' cannot be resolved.',
1074  E_WARNING
1075  );
1076  }
1077  }
1078 
1079  if ($flags & STREAM_URL_STAT_LINK) {
1080  return @lstat($path);
1081  }
1082 
1083  return @stat($path);
1084  }

Member Data Documentation

Hoa\Core\Protocol\Wrapper::$_stream = null
private

Definition at line 585 of file Protocol.php.

Hoa\Core\Protocol\Wrapper::$_streamName = null
private

Definition at line 592 of file Protocol.php.

Hoa\Core\Protocol\Wrapper::$context = null

Definition at line 599 of file Protocol.php.


The documentation for this class was generated from the following file: