Arquivos
hhvm/hphp/test/slow/ext_iterator/1798.php
T
Paul Tarjan 7f4e3c39d6 implement SplFileObject
This diff started off with trying to actually build `SplFileObject` since it was just stubbed out. But then I had to implement everything that extended from it since C++ classes can't extend PHP classes. And then it ballooend into what you see here. I actually think this is better in the long run, so that's why I kept going down this road.

The only thing that doesn't work in pure PHP is `sscanf`. @mwilliams has a fix for that. We need variable args by reference.

I implemented `RecursiveIteratorIterator` in a similar way to our C++ code instead of copying Zend. It translated to PHP a bit nicer. We still don't support the `RecursiveTreeIterator`, but I havn't come accross a need for that yet. I changed the implementation to actually use the `getChildren()` methods instead of peaking inside the `RecursiveDirectoryIterator`.
2013-06-03 10:55:24 -07:00

83 linhas
2.2 KiB
PHP

<?php
$sample_dir = __DIR__.'/../../sample_dir';
$files = array();
foreach (new DirectoryIterator($sample_dir.'/') as $file) {
$files[] = $file;
}
var_dump(count($files));
$dir = new DirectoryIterator($sample_dir.'/');
$files = array();
// order changes per machine
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$files[] = $fileinfo->getFilename();
}
}
asort($files);
var_dump(array_values($files));
$iterator = new DirectoryIterator($sample_dir);
$files = array();
// order changes per machine
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
$str = "BEGIN:\n";
$name = $fileinfo->getFilename();
$str .= $name . "\n";
$fileinfo->getCTime() . "\n";
$fileinfo->getBasename() . "\n";
$fileinfo->getBasename('.cpp') . "\n";
$fileinfo->getGroup() . "\n";
$fileinfo->getInode() . "\n";
$fileinfo->getMTime() . "\n";
$fileinfo->getOwner() . "\n";
$fileinfo->getPerms() . "\n";
$fileinfo->getSize() . "\n";
$fileinfo->getType() . "\n";
$fileinfo->isDir() . "\n";
$fileinfo->isDot() . "\n";
$fileinfo->isExecutable() . "\n";
$fileinfo->isLink() . "\n";
$fileinfo->isReadable() . "\n";
$fileinfo->isWritable() . "\n";
$str .= "END\n";
$files[$name] = $str;
}
}
ksort($files);
foreach ($files as $str) {
echo $str;
}
$iterator = new RecursiveDirectoryIterator($sample_dir);
$files = array();
// order changes per machine
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
$files[$fileinfo->getFilename()] = $fileinfo;
}
}
ksort($files);
foreach ($files as $name => $fileinfo) {
echo $fileinfo->getFilename() . "\n";
$fileinfo->getCTime() . "\n";
$fileinfo->getBasename() . "\n";
$fileinfo->getBasename('.cpp') . "\n";
$fileinfo->getFilename() . "\n";
$fileinfo->getGroup() . "\n";
$fileinfo->getInode() . "\n";
$fileinfo->getMTime() . "\n";
$fileinfo->getOwner() . "\n";
$fileinfo->getPerms() . "\n";
$fileinfo->getSize() . "\n";
$fileinfo->getType() . "\n";
$fileinfo->isDir() . "\n";
$fileinfo->isExecutable() . "\n";
$fileinfo->isLink() . "\n";
$fileinfo->isReadable() . "\n";
$fileinfo->isWritable() . "\n";
}