2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Control\Tests\RequestHandlingTest;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
2017-06-22 12:50:45 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2016-10-14 03:30:05 +02:00
|
|
|
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
|
|
|
|
{
|
2017-03-02 03:24:38 +01:00
|
|
|
private static $url_segment = 'TestController';
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
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();
|
2017-06-22 12:50:45 +02:00
|
|
|
if (Controller::has_curr()) {
|
|
|
|
$this->setRequest(Controller::curr()->getRequest());
|
|
|
|
}
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function index(HTTPRequest $request)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
return "This is the controller";
|
|
|
|
}
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function method(HTTPRequest $request)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
return "This is a method on the controller: " . $request->param('ID') . ', ' . $request->param('OtherID');
|
|
|
|
}
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function legacymethod(HTTPRequest $request)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
return "\$this->urlParams can be used, for backward compatibility: " . $this->urlParams['ID'] . ', '
|
|
|
|
. $this->urlParams['OtherID'];
|
|
|
|
}
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
public function virtualfile(HTTPRequest $request)
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
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');
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
}
|