pen4education
WHAT IS A
STREAM?
A stream is a body of water
[1]
with a current,
confined within a bed and stream banks.
Depending on its location or certa...
?
DATA
FLOW
INPUT
OUTPUT
DATA
PHP
F* FILE*
fopen
fpassthru
fputcsv
fputs
fread
fscanf
fseek
fstat
ftell
ftruncate
fwrite
file_​exists
file_​get_​contents
file_​put_​...
fopen
fpassthru
fputcsv
fputs
fread
fscanf
fseek
fstat
ftell
ftruncate
fwrite
file_​exists
file_​get_​contents
file_​put_​...
fopen(‘file.txt’, ‘r+’);
file_​get_​contents(
‘file.txt’
);
WRAPPERS
file:// — Accessing local filesystem
http:// — Accessing HTTP(s) URLs
ftp:// — Accessing FTP(s) URLs
php:// — Accessing va...
1) file://
fopen(
‘file.txt’, ‘r+’
);
fopen(
‘file://file.txt’, ‘r+’
);
!= ?
2) http://
print file_get_contents(
'http://marabesi.
com'
);
$contexto = stream_context_create([
'http' => [
'method' => 'POST'
'header' => 'Content-Type:
application/x-www-form-urlen...
print file_get_contents(
http://marabesi.com',
false,
$context
);
$fp = fopen(
'http://marabesi.com',
'r',
false,
$context
);
print fgets($fp);
http://php.net/manual/en/context.php
3) ftp://
$fp = fopen(
'ftp://usuario:senha' .
'@meu_servidor.com' .
'/home/matheusmarabesi/index.php',
'r'
);
4) php://
$put = fopen(
'php://stdin, 'r'
);
print fgets($put);
6) data://
print file_get_contents(
'data://text/plain, Utilizando o
wrapper data://'
);
print file_get_contents(
'data://text/plain, Utilizando o
wrapper data://'
);
<img src="data:
image/jpeg;base64,
YXNodXNhdXNhdWlzYXVzYWl1"
/>
print file_get_contents( 'data:
//text/plain;base64,
VXRpbGl6YW5kbyBzdHJlYW1zIGVtIFBIUCAh');
7) glob://
$diretorio = new
RecursiveDirectoryIterator(
'/var/www'
);
1
$iterator = new
RecursiveIteratorIterator(
$diretorio
);
2
$arquivos = new RegexIterator(
$iterator, '/^.+.php/',
RecursiveRegexIterator::GET_MATCH
);
3
$diretorio = new RecursiveDirectoryIterator('/var/www');
$iterator = new RecursiveIteratorIterator($diretorio);
$arquivos ...
$diretorio = new
RecursiveDirectoryIterator(
'glob://var/www/*.php'
);
foreach ($diretorio as $arquivos) {
print $arquivos...
8) ogg://
8) ogg://
9) mandinga://
streamWrapper {
public resource $context ;
__construct ( void )
__destruct ( void )
public bool dir_closedir ( void )
publ...
class Mandinga {
private $arquivo;
public function stream_open($arquivo, $modo)
{
if (!file_exists($arquivo)) {
throw new ...
public function stream_read($bytes)
{
return fread($this->file,
$bytes);
}
public function stream_eof()
{
return feof($thi...
stream_register_wrapper
stream_wrapper_register
!= ?
stream_register_wrapper(
'mandinga', 'Mandinga'
);
stream_register_wrapper(
'mandinga', 'Mandinga'
);
ALIAS
CLASS NAME
print file_get_contents(
mandinga://pessoas.txt'
);
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
Próximos SlideShares
Carregando em…5
×

TDC2016SP - Become a jedi with PHP streams

90 visualizações

Publicada em

Become a jedi with PHP streams

Publicada em: Educação
  • Seja o primeiro a comentar

TDC2016SP - Become a jedi with PHP streams

  1. 1. pen4education
  2. 2. WHAT IS A STREAM?
  3. 3. A stream is a body of water [1] with a current, confined within a bed and stream banks. Depending on its location or certain characteristics, a stream may be referred to as a branch, brook, beck, burn, creek, crick, gill (occasionally ghyll), kill, lick, mill race, rill, river, syke, bayou, rivulet, streamage, wash, run, or runnel. https://en.wikipedia.org/wiki/Stream
  4. 4. ?
  5. 5. DATA FLOW
  6. 6. INPUT OUTPUT DATA
  7. 7. PHP
  8. 8. F* FILE*
  9. 9. fopen fpassthru fputcsv fputs fread fscanf fseek fstat ftell ftruncate fwrite file_​exists file_​get_​contents file_​put_​contents file fileatime filectime filegroup fileinode filemtime fileowner fileperms
  10. 10. fopen fpassthru fputcsv fputs fread fscanf fseek fstat ftell ftruncate fwrite file_​exists file_​get_​contents file_​put_​contents file fileatime filectime filegroup fileinode filemtime fileowner fileperms RESOURCE FILE PATH
  11. 11. fopen(‘file.txt’, ‘r+’); file_​get_​contents( ‘file.txt’ );
  12. 12. WRAPPERS
  13. 13. file:// — Accessing local filesystem http:// — Accessing HTTP(s) URLs ftp:// — Accessing FTP(s) URLs php:// — Accessing various I/O streams zlib:// — Compression Streams data:// — Data (RFC 2397) glob:// — Find pathnames matching pattern phar:// — PHP Archive ssh2:// — Secure Shell 2 rar:// — RAR ogg:// — Audio streams
  14. 14. 1) file://
  15. 15. fopen( ‘file.txt’, ‘r+’ ); fopen( ‘file://file.txt’, ‘r+’ ); != ?
  16. 16. 2) http://
  17. 17. print file_get_contents( 'http://marabesi. com' );
  18. 18. $contexto = stream_context_create([ 'http' => [ 'method' => 'POST' 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => 'livro=php' ] ]);
  19. 19. print file_get_contents( http://marabesi.com', false, $context );
  20. 20. $fp = fopen( 'http://marabesi.com', 'r', false, $context ); print fgets($fp);
  21. 21. http://php.net/manual/en/context.php
  22. 22. 3) ftp://
  23. 23. $fp = fopen( 'ftp://usuario:senha' . '@meu_servidor.com' . '/home/matheusmarabesi/index.php', 'r' );
  24. 24. 4) php://
  25. 25. $put = fopen( 'php://stdin, 'r' ); print fgets($put);
  26. 26. 6) data://
  27. 27. print file_get_contents( 'data://text/plain, Utilizando o wrapper data://' );
  28. 28. print file_get_contents( 'data://text/plain, Utilizando o wrapper data://' );
  29. 29. <img src="data: image/jpeg;base64, YXNodXNhdXNhdWlzYXVzYWl1" />
  30. 30. print file_get_contents( 'data: //text/plain;base64, VXRpbGl6YW5kbyBzdHJlYW1zIGVtIFBIUCAh');
  31. 31. 7) glob://
  32. 32. $diretorio = new RecursiveDirectoryIterator( '/var/www' ); 1
  33. 33. $iterator = new RecursiveIteratorIterator( $diretorio ); 2
  34. 34. $arquivos = new RegexIterator( $iterator, '/^.+.php/', RecursiveRegexIterator::GET_MATCH ); 3
  35. 35. $diretorio = new RecursiveDirectoryIterator('/var/www'); $iterator = new RecursiveIteratorIterator($diretorio); $arquivos = new RegexIterator( $iterator, '/^.+.php/', RecursiveRegexIterator::GET_MATCH ); foreach ($diretorio as $arquivos) { print $arquivos->getFilename(); }
  36. 36. $diretorio = new RecursiveDirectoryIterator( 'glob://var/www/*.php' ); foreach ($diretorio as $arquivos) { print $arquivos->getFilename(); }
  37. 37. 8) ogg://
  38. 38. 8) ogg://
  39. 39. 9) mandinga://
  40. 40. streamWrapper { public resource $context ; __construct ( void ) __destruct ( void ) public bool dir_closedir ( void ) public bool dir_opendir ( string $path , int $options ) public string dir_readdir ( void ) public bool dir_rewinddir ( void ) public bool mkdir ( string $path , int $mode , int $options ) public bool rename ( string $path_from , string $path_to ) public bool rmdir ( string $path , int $options ) public resource stream_cast ( int $cast_as ) public void stream_close ( void ) public bool stream_eof ( void ) public bool stream_flush ( void ) public bool stream_lock ( int $operation ) public bool stream_metadata ( string $path , int $option , mixed $value ) public bool stream_open ( string $path , string $mode , int $options , string &$opened_path ) public string stream_read ( int $count ) public bool stream_seek ( int $offset , int $whence = SEEK_SET ) public bool stream_set_option ( int $option , int $arg1 , int $arg2 ) public array stream_stat ( void ) THERE IS MORE
  41. 41. class Mandinga { private $arquivo; public function stream_open($arquivo, $modo) { if (!file_exists($arquivo)) { throw new Exception( 'O arquivo informado não existe' ); $this->arquivo = fopen($arquivo, $modo); return true; } }
  42. 42. public function stream_read($bytes) { return fread($this->file, $bytes); } public function stream_eof() { return feof($this->file); }
  43. 43. stream_register_wrapper stream_wrapper_register != ?
  44. 44. stream_register_wrapper( 'mandinga', 'Mandinga' );
  45. 45. stream_register_wrapper( 'mandinga', 'Mandinga' ); ALIAS CLASS NAME
  46. 46. print file_get_contents( mandinga://pessoas.txt' );

×