API CHANGE #2698 ajshort: URL handler only passes control to subclasses of RequestHandlingData

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64951 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-10-30 21:51:59 +00:00
parent ae0bbfb2c0
commit 672ca89c0b
5 changed files with 13 additions and 3 deletions

View File

@ -330,7 +330,7 @@ class HTTPRequest extends Object implements ArrayAccess {
if($varRequired && !isset($this->dirParts[$i])) return false; if($varRequired && !isset($this->dirParts[$i])) return false;
$arguments[$varName] = isset($this->dirParts[$i]) ? $this->dirParts[$i] : null; $arguments[$varName] = isset($this->dirParts[$i]) ? $this->dirParts[$i] : null;
if($part == '$Controller' && !class_exists($arguments['Controller'])) { if($part == '$Controller' && (!class_exists($arguments['Controller']) || !is_subclass_of($arguments['Controller'], 'RequestHandlingData'))) {
return false; return false;
} }

View File

@ -2632,7 +2632,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
* which could cause horrible bugs. * which could cause horrible bugs.
*/ */
public static function set_context_obj($obj) { public static function set_context_obj($obj) {
if($obj && self::$context_obj) user_error("Dataobject::set_context_obj called when there is already a context.", E_USER_WARNING); if($obj && self::$context_obj) user_error("Dataobject::set_context_obj passed " . $obj->class . "." . $obj->ID . " when there is already a context: " . self::$context_obj->class . '.' . self::$context_obj->ID, E_USER_WARNING);
self::$context_obj = $obj; self::$context_obj = $obj;
} }

View File

@ -865,7 +865,10 @@ class SiteTree extends DataObject {
''; '';
$count = 1; $count = 1;
while(class_exists($this->URLSegment) || DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter")) { while (
(class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandlingData')) ||
DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter")
) {
$count++; $count++;
$this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count"; $this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count";
} }

View File

@ -12,6 +12,7 @@ class SiteTreeTest extends SapphireTest {
* - Turns things into lowercase-hyphen-format * - Turns things into lowercase-hyphen-format
* - Generates from Title by default, unless URLSegment is explicitly set * - Generates from Title by default, unless URLSegment is explicitly set
* - Resolves duplicates by appending a number * - Resolves duplicates by appending a number
* - renames classes with a class name conflict
*/ */
function testURLGeneration() { function testURLGeneration() {
$expectedURLs = array( $expectedURLs = array(
@ -23,6 +24,8 @@ class SiteTreeTest extends SapphireTest {
'product2' => 'another-product', 'product2' => 'another-product',
'product3' => 'another-product-2', 'product3' => 'another-product-2',
'product4' => 'another-product-3', 'product4' => 'another-product-3',
'object' => 'object',
'controller' => 'controller-2'
); );
foreach($expectedURLs as $fixture => $urlSegment) { foreach($expectedURLs as $fixture => $urlSegment) {

View File

@ -23,6 +23,10 @@ Page:
Title: Another Product Title: Another Product
contact: contact:
Title: Contact Us Title: Contact Us
object:
Title: Object
controller:
Title: Controller
ErrorPage: ErrorPage:
404: 404: