Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Http Class Reference
Inheritance diagram for Http:
File DriverInterface Https

Public Member Functions

 isExists ($path)
 
 stat ($path)
 
 fileGetContents ($path, $flags=null, $context=null)
 
 filePutContents ($path, $content, $mode=null, $context=null)
 
 fileOpen ($path, $mode)
 
 fileReadLine ($resource, $length, $ending=null)
 
 getAbsolutePath ($basePath, $path, $scheme=null)
 
- Public Member Functions inherited from File
 isExists ($path)
 
 stat ($path)
 
 isReadable ($path)
 
 isFile ($path)
 
 isDirectory ($path)
 
 fileGetContents ($path, $flag=null, $context=null)
 
 isWritable ($path)
 
 getParentDirectory ($path)
 
 createDirectory ($path, $permissions=0777)
 
 search ($pattern, $path)
 
 rename ($oldPath, $newPath, DriverInterface $targetDriver=null)
 
 copy ($source, $destination, DriverInterface $targetDriver=null)
 
 symlink ($source, $destination, DriverInterface $targetDriver=null)
 
 deleteFile ($path)
 
 changePermissions ($path, $permissions)
 
 touch ($path, $modificationTime=null)
 
 filePutContents ($path, $content, $mode=null)
 
 fileOpen ($path, $mode)
 
 fileReadLine ($resource, $length, $ending=null)
 
 fileRead ($resource, $length)
 
 fileGetCsv ($resource, $length=0, $delimiter=',', $enclosure='"', $escape = '\\')
 
 fileTell ($resource)
 
 fileSeek ($resource, $offset, $whence=SEEK_SET)
 
 endOfFile ($resource)
 
 fileClose ($resource)
 
 fileWrite ($resource, $data)
 
 fileFlush ($resource)
 
 fileLock ($resource, $lockMode=LOCK_EX)
 
 fileUnlock ($resource)
 
 getAbsolutePath ($basePath, $path, $scheme=null)
 
 getRelativePath ($basePath, $path=null)
 
 getRealPath ($path)
 
 getRealPathSafety ($path)
 
- Public Member Functions inherited from DriverInterface
 readDirectory ($path)
 
 readDirectoryRecursively ($path=null)
 
 deleteDirectory ($path)
 
 changePermissionsRecursively ($path, $dirPermissions, $filePermissions)
 
 filePutCsv ($resource, array $data, $delimiter=',', $enclosure='"')
 

Protected Member Functions

 getScheme ($scheme=null)
 
 open ($hostname, $port)
 
 parseUrl ($path)
 
- Protected Member Functions inherited from File
 getWarningMessage ()
 
 fixSeparator ($path)
 
 getScheme ($scheme=null)
 

Protected Attributes

 $scheme = 'http'
 
- Protected Attributes inherited from File
 $scheme = ''
 

Additional Inherited Members

- Data Fields inherited from DriverInterface
const WRITEABLE_DIRECTORY_MODE = 0770
 
const WRITEABLE_FILE_MODE = 0660
 

Detailed Description

Class Http

Definition at line 17 of file Http.php.

Member Function Documentation

◆ fileGetContents()

fileGetContents (   $path,
  $flags = null,
  $context = null 
)

Retrieve file contents from given path

Parameters
string$path
string | null$flags
resource | null$context
Returns
string
Exceptions
FileSystemException

Implements DriverInterface.

Definition at line 88 of file Http.php.

89  {
90  clearstatcache();
91  $result = @file_get_contents($this->getScheme() . $path, $flags, $context);
92  if (false === $result) {
93  throw new FileSystemException(
94  new \Magento\Framework\Phrase(
95  'The contents from the "%1" file can\'t be read. %2',
96  [$path, $this->getWarningMessage()]
97  )
98  );
99  }
100  return $result;
101  }

◆ fileOpen()

fileOpen (   $path,
  $mode 
)

Open file

Parameters
string$path
string$mode
Returns
resource file
Exceptions
FileSystemException@SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements DriverInterface.

Definition at line 136 of file Http.php.

137  {
138  $urlProp = $this->parseUrl($this->getScheme() . $path);
139 
140  if (false === $urlProp) {
141  throw new FileSystemException(
142  new \Magento\Framework\Phrase('The download URL is incorrect. Verify and try again.')
143  );
144  }
145 
146  $hostname = $urlProp['host'];
147  $port = 80;
148 
149  if (isset($urlProp['port'])) {
150  $port = (int)$urlProp['port'];
151  }
152 
153  $path = '/';
154  if (isset($urlProp['path'])) {
155  $path = $urlProp['path'];
156  }
157 
158  $query = '';
159  if (isset($urlProp['query'])) {
160  $query = '?' . $urlProp['query'];
161  }
162 
163  $result = $this->open($hostname, $port);
164 
165  $headers = 'GET ' .
166  $path .
167  $query .
168  ' HTTP/1.0' .
169  "\r\n" .
170  'Host: ' .
171  $hostname .
172  "\r\n" .
173  'User-Agent: Magento' .
174  "\r\n" .
175  'Connection: close' .
176  "\r\n" .
177  "\r\n";
178 
179  fwrite($result, $headers);
180 
181  // trim headers
182  while (!feof($result)) {
183  $str = fgets($result, 1024);
184  if ($str == "\r\n") {
185  break;
186  }
187  }
188 
189  return $result;
190  }

◆ filePutContents()

filePutContents (   $path,
  $content,
  $mode = null,
  $context = null 
)

Open file in given path

Parameters
string$path
string$content
string | null$mode
resource | null$context
Returns
int The number of bytes that were written
Exceptions
FileSystemException

Definition at line 113 of file Http.php.

114  {
115  $result = @file_put_contents($this->getScheme() . $path, $content, $mode, $context);
116  if (!$result) {
117  throw new FileSystemException(
118  new \Magento\Framework\Phrase(
119  'The specified "%1" file couldn\'t be written. %2',
120  [$path, $this->getWarningMessage()]
121  )
122  );
123  }
124  return $result;
125  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

◆ fileReadLine()

fileReadLine (   $resource,
  $length,
  $ending = null 
)

Reads the line content from file pointer (with specified number of bytes from the current position).

Parameters
resource$resource
int$length
string$ending[optional]
Returns
string
Exceptions
FileSystemException

Implements DriverInterface.

Definition at line 201 of file Http.php.

202  {
203  $result = @stream_get_line($resource, $length, $ending);
204 
205  return $result;
206  }
$resource
Definition: bulk.php:12

◆ getAbsolutePath()

getAbsolutePath (   $basePath,
  $path,
  $scheme = null 
)

Get absolute path

Parameters
string$basePath
string$path
string | null$scheme
Returns
string @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements DriverInterface.

Definition at line 217 of file Http.php.

218  {
219  // check if the path given is already an absolute path containing the
220  // basepath. so if the basepath starts at position 0 in the path, we
221  // must not concatinate them again because path is already absolute.
222  if (0 === strpos($path, $basePath)) {
223  return $this->getScheme() . $path;
224  }
225 
226  return $this->getScheme() . $basePath . $path;
227  }

◆ getScheme()

getScheme (   $scheme = null)
protected

Return path with scheme

Parameters
null | string$scheme
Returns
string

Definition at line 235 of file Http.php.

236  {
238  return $scheme ? $scheme . '://' : '';
239  }

◆ isExists()

isExists (   $path)

Checks if path exists

Parameters
string$path
Returns
bool
Exceptions
FileSystemException

Implements DriverInterface.

Definition at line 33 of file Http.php.

34  {
35  $headers = array_change_key_case(get_headers($this->getScheme() . $path, 1), CASE_LOWER);
36 
37  $status = $headers[0];
38 
39  if (strpos($status, '200 OK') === false) {
40  $result = false;
41  } else {
42  $result = true;
43  }
44 
45  return $result;
46  }
$status
Definition: order_status.php:8

◆ open()

open (   $hostname,
  $port 
)
protected

Open a url

Parameters
string$hostname
int$port
Exceptions

Definition at line 249 of file Http.php.

250  {
251  $result = @fsockopen($hostname, $port, $errorNumber, $errorMessage);
252  if ($result === false) {
253  throw new FileSystemException(
254  new \Magento\Framework\Phrase(
255  'Something went wrong while connecting to the host. Error#%1 - %2.',
256  [$errorNumber, $errorMessage]
257  )
258  );
259  }
260  return $result;
261  }
fsockopen(&$errorNumber, &$errorMessage)
Definition: http_mock.php:37

◆ parseUrl()

parseUrl (   $path)
protected

Parse a http url

Parameters
string$path
Returns
array

Definition at line 269 of file Http.php.

270  {
271  return parse_url($path);
272  }

◆ stat()

stat (   $path)

Gathers the statistics of the given path

Parameters
string$path
Returns
array @SuppressWarnings(PHPMD.NPathComplexity)

Implements DriverInterface.

Definition at line 55 of file Http.php.

56  {
57  $headers = array_change_key_case(get_headers($this->getScheme() . $path, 1), CASE_LOWER);
58 
59  $result = [
60  'dev' => 0,
61  'ino' => 0,
62  'mode' => 0,
63  'nlink' => 0,
64  'uid' => 0,
65  'gid' => 0,
66  'rdev' => 0,
67  'atime' => 0,
68  'ctime' => 0,
69  'blksize' => 0,
70  'blocks' => 0,
71  'size' => isset($headers['content-length']) ? $headers['content-length'] : 0,
72  'type' => isset($headers['content-type']) ? $headers['content-type'] : '',
73  'mtime' => isset($headers['last-modified']) ? $headers['last-modified'] : 0,
74  'disposition' => isset($headers['content-disposition']) ? $headers['content-disposition'] : null,
75  ];
76  return $result;
77  }

Field Documentation

◆ $scheme

$scheme = 'http'
protected

Definition at line 24 of file Http.php.


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