Commit 3183decd authored by Christoph Dörfel's avatar Christoph Dörfel Committed by Nicole Cordes
Browse files

[BUGFIX] Allow closures in filters methods for directory items

Instead of checking if a given filter is callable a is_array check
is done. But the filter can also be a closure and a is_array would
fail then.

This patch changes the is_array check to is_callable.

Resolves: #65244
Releases: master, 6.2
Change-Id: I1a1e9ce0e789bd36a4fa36e91389e8b62c50116e
Reviewed-on: http://review.typo3.org/37153


Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
parent dba72f3d
......@@ -410,7 +410,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
*/
protected function applyFilterMethodsToDirectoryItem(array $filterMethods, $itemName, $itemIdentifier, $parentIdentifier) {
foreach ($filterMethods as $filter) {
if (is_array($filter)) {
if (is_callable($filter)) {
$result = call_user_func($filter, $itemName, $itemIdentifier, $parentIdentifier, array(), $this);
// We have to use -1 as the „don't include“ return value, as call_user_func() will return FALSE
// If calling the method succeeded and thus we can't use that as a return value.
......
......@@ -1545,4 +1545,40 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
$this->createDriver()->sanitizeFileName('');
}
/**
* @test
*/
public function applyFilterMethodsToDirectoryItemCallsFilterMethodIfClosure() {
$this->setExpectedException('Exception', 'I was called!');
$closure = function() {
throw new \Exception('I was called!');
};
$filterMethods = array(
$closure,
);
$this->createDriver()->_call('applyFilterMethodsToDirectoryItem', $filterMethods, '', '', '');
}
/**
* @test
*/
public function applyFilterMethodsToDirectoryItemCallsFilterMethodIfName() {
$dummyObject = $this
->getMockBuilder('\TYPO3\CMS\Core\Resource\Driver\LocalDriver')
->setMethods(array('dummy'))
->disableOriginalConstructor()
->getMock();
$method = array(
$dummyObject,
'dummy',
);
$dummyObject->expects($this->once())->method('dummy');
$filterMethods = array(
$method,
);
$this->createDriver()->_call('applyFilterMethodsToDirectoryItem', $filterMethods, '', '', '');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment