silverstripe-framework/tests/php/Control/RequestHandlingTest/TestController.php
Damian Mooyman 0c41a97a8b API Refactor Form request handling into FormRequestHandler
API Add HasRequestHandler interface
API Refactor Link() and url handling behaviour from Controller into RequestHandler
API RequestHandler classes now must define url_segment to have a default Link()
API Clean up redirectBack()
2017-03-10 15:04:33 +13:00

102 lines
2.5 KiB
PHP

<?php
namespace SilverStripe\Control\Tests\RequestHandlingTest;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\View\SSViewer;
/**
* Controller for the test
*/
class TestController extends Controller implements TestOnly
{
private static $url_segment = 'TestController';
private static $allowed_actions = array(
'method',
'legacymethod',
'virtualfile',
'TestForm',
'throwexception',
'throwresponseexception',
'throwhttperror',
);
private static $url_handlers = array(
// The double-slash is need here to ensure that
'$Action//$ID/$OtherID' => "handleAction",
);
private static $extensions = array(
ControllerExtension::class,
AllowedControllerExtension::class,
);
public function __construct()
{
$this->failover = new ControllerFailover();
parent::__construct();
}
public function index($request)
{
return "This is the controller";
}
public function method($request)
{
return "This is a method on the controller: " . $request->param('ID') . ', ' . $request->param('OtherID');
}
public function legacymethod($request)
{
return "\$this->urlParams can be used, for backward compatibility: " . $this->urlParams['ID'] . ', '
. $this->urlParams['OtherID'];
}
public function virtualfile($request)
{
return "This is the virtualfile method";
}
public function TestForm()
{
return new TestForm(
$this,
"TestForm",
new FieldList(
new TestFormField("MyField"),
new SubclassedFormField("SubclassedField")
),
new FieldList(
new FormAction("myAction")
)
);
}
public function throwexception()
{
throw new HTTPResponse_Exception('This request was invalid.', 400);
}
public function throwresponseexception()
{
throw new HTTPResponse_Exception(new HTTPResponse('There was an internal server error.', 500));
}
public function throwhttperror()
{
$this->httpError(404, 'This page does not exist.');
}
public function getViewer($action)
{
return new SSViewer('BlankPage');
}
}