Hoa central
Temporary.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\File\Temporary;
38 
39 use Hoa\Core;
40 use Hoa\File;
41 
50 class Temporary extends File
51 {
57  private static $_i = 0;
58 
59 
60 
72  public function __construct(
73  $streamName,
74  $mode,
75  $context = null,
76  $wait = false
77  ) {
78  if (null === $streamName) {
79  $streamName = 'hoa://Library/File/Temporary.php#' . self::$_i++;
80  }
81 
82  parent::__construct($streamName, $mode, $context, $wait);
83 
84  return;
85  }
86 
96  protected function &_open($streamName, \Hoa\Stream\Context $context = null)
97  {
98  if (false === $out = @tmpfile()) {
99  throw new File\Exception(
100  'Failed to open a temporary stream.',
101  0
102  );
103  }
104 
105  return $out;
106  }
107 
121  public static function create($directory = null, $prefix = '__hoa_')
122  {
123  if (null === $directory ||
124  false === is_dir($directory)) {
125  $directory = static::getTemporaryDirectory();
126  }
127 
128  return tempnam($directory, $prefix);
129  }
130 
136  public static function getTemporaryDirectory()
137  {
138  return sys_get_temp_dir();
139  }
140 }
141 
145 Core\Consistency::flexEntity('Hoa\File\Temporary\Temporary');
& _open($streamName,\Hoa\Stream\Context $context=null)
Definition: Temporary.php:96
__construct($streamName, $mode, $context=null, $wait=false)
Definition: Temporary.php:72
static create($directory=null, $prefix= '__hoa_')
Definition: Temporary.php:121