allow for prodiving an override method processor to backend filesystem
This commit is contained in:
parent
42ee62fbc3
commit
e02cfc4df6
@ -120,7 +120,7 @@ class ComicPressBackendFilesystemFactory {
|
||||
return $return;
|
||||
}
|
||||
|
||||
function process_search_string($post, $type, $filename = null) {
|
||||
function process_search_string($post, $type, $filename = null, $replace_object = null) {
|
||||
$this->_searches = array($this->search_string);
|
||||
$this->_filename = $filename;
|
||||
|
||||
@ -135,16 +135,23 @@ class ComicPressBackendFilesystemFactory {
|
||||
'_replace_' . strtolower(str_replace('-', '_', $matches[1])) => null,
|
||||
'_replace_' . strtolower($parts[0]) => implode('-', array_slice($parts, 1))
|
||||
) as $method => $additional) {
|
||||
if (method_exists($this, $method)) {
|
||||
$any_found = true;
|
||||
$found = true;
|
||||
$result = $this->{$method}($post, $type, $additional);
|
||||
if ($result !== false) {
|
||||
$this->_searches[$i] = str_replace($matches[0], $result, $search);
|
||||
break;
|
||||
} else {
|
||||
// array state change, start over
|
||||
break;
|
||||
$object_calls = array($this);
|
||||
if (is_object($replace_object)) {
|
||||
array_unshift($object_calls, $replace_object);
|
||||
}
|
||||
|
||||
foreach ($object_calls as $obj) {
|
||||
if (method_exists($obj, $method)) {
|
||||
$any_found = true;
|
||||
$found = true;
|
||||
$result = $obj->{$method}($post, $type, $additional);
|
||||
if ($result !== false) {
|
||||
$this->_searches[$i] = str_replace($matches[0], $result, $search);
|
||||
break 2;
|
||||
} else {
|
||||
// array state change, start over
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -393,4 +393,18 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase
|
||||
)
|
||||
), $fa->get_urls_for_post_roots($roots, (object)array('post_date' => '2010-01-01')));
|
||||
}
|
||||
|
||||
function testProvideReplaceObject() {
|
||||
$fa = $this->getMock('ComicPressBackendFilesystemFactory', array('_replace_wordpress', '_replace_type'));
|
||||
|
||||
$fa->search_string = '%wordpress%/%type%';
|
||||
|
||||
$fa->expects($this->once())->method('_replace_wordpress')->will($this->returnValue('wordpress'));
|
||||
$fa->expects($this->never())->method('_replace_type');
|
||||
|
||||
$replace = $this->getMock('ReplaceObject', array('_replace_type'));
|
||||
$replace->expects($this->once())->method('_replace_type')->will($this->returnValue('type'));
|
||||
|
||||
$this->assertEquals(array('wordpress/type'), $fa->process_search_string(null, 'type', null, $replace));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user