-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from magento-ogre/PR_Branch
[Ogres] Bug fixes
- Loading branch information
Showing
15 changed files
with
314 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
lib/internal/Magento/Framework/Filesystem/Filter/ExcludeFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Filesystem\Filter; | ||
|
||
/** | ||
* Filters Iterator to exclude specified files | ||
*/ | ||
class ExcludeFilter extends \FilterIterator | ||
{ | ||
/** | ||
* Array that is used for filtering | ||
* | ||
* @var array | ||
*/ | ||
protected $_filters; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Iterator $iterator | ||
* @param array $filters list of files to skip | ||
*/ | ||
public function __construct(\Iterator $iterator, array $filters) | ||
{ | ||
parent::__construct($iterator); | ||
$this->_filters = $filters; | ||
} | ||
|
||
/** | ||
* Check whether the current element of the iterator is acceptable | ||
* | ||
* @return bool | ||
*/ | ||
public function accept() | ||
{ | ||
$current = str_replace('\\', '/', $this->current()->__toString()); | ||
$currentFilename = str_replace('\\', '/', $this->current()->getFilename()); | ||
|
||
if ($currentFilename == '.' || $currentFilename == '..') { | ||
return false; | ||
} | ||
|
||
foreach ($this->_filters as $filter) { | ||
$filter = str_replace('\\', '/', $filter); | ||
if (false !== strpos($current, $filter)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ExcludeFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Filesystem\Test\Unit\File; | ||
|
||
use \Magento\Framework\Filesystem\Filter\ExcludeFilter; | ||
|
||
/** | ||
* Class ExcludeFilterTest | ||
*/ | ||
class ExcludeFilterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Iterator | ||
*/ | ||
protected $iterator; | ||
|
||
protected function setUp() | ||
{ | ||
$this->iterator = $this->getFilesIterator(); | ||
} | ||
|
||
public function testExclusion() | ||
{ | ||
$iterator = new ExcludeFilter( | ||
$this->iterator, | ||
[ | ||
BP . '/var/session/' | ||
] | ||
); | ||
|
||
foreach ($iterator as $i) { | ||
$result[] = $i; | ||
} | ||
|
||
$this->assertTrue(!in_array(BP . '/var/session/', $result), 'Filtered path should not be in array'); | ||
} | ||
|
||
private function getFilesIterator () | ||
{ | ||
$files = [ | ||
BP . '/var/', | ||
BP . '/var/session/', | ||
BP . '/var/cache/' | ||
]; | ||
|
||
foreach ($files as $file) { | ||
$item = $this->getMockBuilder('SplFileInfoClass')->setMethods(['__toString', 'getFilename'])->getMock(); | ||
$item->expects($this->any())->method('__toString')->willReturn($file); | ||
$item->expects($this->any())->method('getFilename')->willReturn('notDots'); | ||
yield $item; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.