本文整理汇总了PHP中CakeRequest::addParams方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeRequest::addParams方法的具体用法?PHP CakeRequest::addParams怎么用?PHP CakeRequest::addParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeRequest
的用法示例。
在下文中一共展示了CakeRequest::addParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _apiRequest
/**
* Helper method to create an test API request (with the appropriate detector)
*/
protected function _apiRequest($params)
{
$request = new CakeRequest();
$request->addParams($params);
$request->addDetector('api', array('callback' => array('CroogoRouter', 'isApiRequest')));
return $request;
}
示例2: testIs
public function testIs()
{
$result = Reveal::is('App.online');
$expected = !in_array(gethostbyname('google.com'), array('google.com', false));
$this->assertEqual($result, $expected);
$result = Reveal::is('DebugKit.loaded');
$expected = CakePlugin::loaded('DebugKit');
$this->assertEqual($result, $expected);
$result = Reveal::is(array('OR' => array('DebugKit.enabled', 'DebugKit.automated')));
$expected = Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun');
$this->assertEqual($result, $expected);
$_GET['debug'] = 'true';
$this->assertTrue(Reveal::is('DebugKit.requested'));
$result = Reveal::is('DebugKit.loaded', array('OR' => array('DebugKit.enabled', array('AND' => array('DebugKit.automated', 'DebugKit.requested')))));
$expected = CakePlugin::loaded('DebugKit') || Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun') && isset($_GET['debug']) && 'true' == $_GET['debug'];
$this->assertEqual($result, $expected);
$this->assertEqual(Reveal::is('DebugKit.running'), $expected);
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('controller' => 'pages', 'action' => 'display', 'pass' => array('home'))));
$result = Reveal::is('Page.front');
$this->assertTrue($result);
Router::reload();
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('prefix' => 'admin', 'admin' => true)));
$result = Reveal::is('Page.prefixed');
$this->assertTrue($result);
Router::reload();
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('controller' => 'users', 'action' => 'login')));
$result = Reveal::is('Page.login');
$this->assertTrue($result);
$this->assertTrue(Reveal::is('Page.test'));
}
示例3: beforeDispatch
/**
* beforeDispatch Event
*
* @param CakeEvent $event イベント
* @return void|CakeResponse
*/
public function beforeDispatch(CakeEvent $event)
{
$request = $event->data['request'];
$response = $event->data['response'];
if (!empty($request->params['Content'])) {
return;
} else {
if ($this->_existController($request)) {
return;
}
}
$site = BcSite::findCurrent();
if (!$site || !$site->enabled) {
return;
}
$mainSite = $site->getMain();
if (!$mainSite) {
return;
}
$mainSiteUrl = '/' . preg_replace('/^' . $site->alias . '\\//', '', $request->url);
if ($mainSite->alias) {
$mainSiteUrl = '/' . $mainSite->alias . $mainSiteUrl;
}
if ($mainSiteUrl) {
$request = new CakeRequest($mainSiteUrl);
$params = Router::parse($request->url);
$request->addParams($params);
if ($this->_existController($request)) {
$response->header('Location', $request->base . $mainSiteUrl);
$response->statusCode(302);
return $response;
}
}
return;
}
示例4: testPrefixedAllowedActions
public function testPrefixedAllowedActions()
{
$request = new CakeRequest('/admin/users/view/3');
$request->addParams(array('admin' => true, 'controller' => 'users', 'action' => 'admin_add', 3));
$response = $this->getMock('CakeRequest');
$this->Controller = new AclFilterTestController($request, $response);
$this->Controller->constructClasses();
$user = array('id' => 3, 'role_id' => 3, 'username' => 'yvonne');
$this->Controller->Session->write('Auth.User', $user);
$aro = array('Role' => array('id' => 3));
$aco = 'controllers/Users/admin_add';
// Role.3 has no access to Users/admin_add yet
$allowed = $this->Controller->Acl->check($aro, $aco);
$this->assertEquals(false, $allowed);
// grant access to /admin/users/view to Role.3
$this->Controller->Acl->allow($aro, $aco);
// new permission active
$allowed = $this->Controller->Acl->check($aro, $aco);
$this->assertEquals(true, $allowed);
// and gets picked up by AclFilterComponent::auth() correctly
$this->Controller->startupProcess();
$this->Controller->AclFilter->auth();
$result = $this->Controller->Auth->allowedActions;
$this->assertEquals(array('admin_add'), $result);
}
示例5: __construct
/**
* construct method
*
* @param CakeRequest $request Current request.
* @param CakeResponse $response Current request.
*/
public function __construct($request, $response)
{
$request->addParams(Router::parse('/auth_test'));
$request->here = '/auth_test';
$request->webroot = '/';
Router::setRequestInfo($request);
parent::__construct($request, $response);
}
示例6: testAuthorizeCheckFailure
/**
* test check() failing
*
* @return void
*/
public function testAuthorizeCheckFailure()
{
$request = new CakeRequest('posts/index', false);
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
$user = array('User' => array('user' => 'mark'));
$this->_mockAcl();
$this->Acl->expects($this->once())->method('check')->with($user, 'Posts', 'read')->will($this->returnValue(false));
$this->assertFalse($this->auth->authorize($user['User'], $request));
}
示例7: _buildFakeRequest
protected function _buildFakeRequest($controllerName, $action, $params = array())
{
$url = '/' . $controllerName . '/' . $action;
if (count($params) > 0) {
$url .= '/' . join($params, '/');
}
$request = new CakeRequest($url, false);
$request->addParams(array('plugin' => null, 'controller' => $controllerName, 'action' => $action, 'pass' => $params));
return $request;
}
示例8: testGetResponses_extUpload
/**
* Tests the getResponses() method in combination with the 'extUpload' request parameter. If this parameter is true,
* the response should not be JSON encoded but rather a valid HTML structure which contains the result inside a
* <textarea>-element.
*
*/
public function testGetResponses_extUpload()
{
$response1 = array('body' => array('message' => 'Hello World'));
$request = new CakeRequest();
$request->addParams(array('controller' => 'foo', 'action' => 'bar', 'extUpload' => true));
$collection = new BanchaResponseCollection();
$collection->addResponse(2, new CakeResponse($response1), $request);
$expected = '<html><body><textarea>[{"type":"rpc","tid":2,"action":"foo","method":"bar",' . '"result":' . json_encode($response1['body']) . ',"extUpload":true}]</textarea></body></html>';
$this->assertEquals($expected, $collection->getResponses()->body());
}
示例9: testLinkstringRuleWithQueryString
public function testLinkstringRuleWithQueryString()
{
$request = new CakeRequest();
$request->addParams(array('controller' => 'nodes', 'plugin' => 'nodes', 'action' => 'index', 'type' => 'blog'));
$request->query = array('page' => '8');
$Filter = new VisibilityFilter($request);
$blocks = $this->_testData();
Configure::write('foo', true);
$results = $Filter->remove($blocks, array('model' => 'Block', 'field' => 'visibility_paths'));
// exact match with query string
$this->assertTrue(Hash::check($results, '{n}.Block[id=6]'));
}
示例10: startTest
public function startTest($method)
{
Router::connect('/', array('controller' => 'document_tests', 'action' => 'index'));
$request = new CakeRequest('/');
$request->addParams(Router::parse('/'));
$this->Controller = new DocumentTestsController($request);
$this->Controller->uses = array('Document');
if (array_search($method, array('testPersistence')) !== false) {
$this->Controller->components = array('Session', 'Filter.Filter' => array('nopersist' => true));
} else {
$this->Controller->components = array('Session', 'Filter.Filter');
}
$this->Controller->constructClasses();
$this->Controller->Session->destroy();
$this->Controller->Components->trigger('initialize', array($this->Controller));
}
示例11: isAuthorized
/**
* Check to see if the currently logged in user is authorized to perform
* an action on a certain controller (with certain params).
* @param string $controller The name of the controller the user wants to act on.
* @param string $action The action the user wants to perform.
* @param array $params Any parameters for the action.
* @return bool True if user is authorized to perform the action, false otherwise.
*/
public function isAuthorized($controller, $action, $params = array())
{
// Build the url and CakeRequest
$url = '/' . $controller . '/' . $action;
if (count($params) > 0) {
$url .= '/' . join($params, '/');
}
$request = new CakeRequest($url, false);
$request->addParams(array('plugin' => null, 'controller' => $controller, 'action' => $action, 'pass' => $params));
// Grab the controller, this may have to create it :(
$controllerObj = $this->__getController($controller);
// Have to call beforeFilter to set-up the auth properly
$controllerObj->beforeFilter();
// First we need to check if the user must be logged in to do this action
$allowedActions = $controllerObj->Auth->allowedActions;
$isAllowed = $allowedActions == array('*') || in_array($action, array_map('strtolower', $allowedActions));
if ($isAllowed) {
return true;
}
$user = AuthComponent::user();
return $controllerObj->Auth->isAuthorized($user, $request);
}
示例12: setRequestInfo
/**
* Takes parameter and path information back from the Dispatcher, sets these
* parameters as the current request parameters that are merged with URL arrays
* created later in the request.
*
* Nested requests will create a stack of requests. You can remove requests using
* Router::popRequest(). This is done automatically when using Object::requestAction().
*
* Will accept either a CakeRequest object or an array of arrays. Support for
* accepting arrays may be removed in the future.
*
* @param CakeRequest|array $request Parameters and path information or a CakeRequest object.
* @return void
*/
public static function setRequestInfo($request)
{
if ($request instanceof CakeRequest) {
self::$_requests[] = $request;
} else {
$requestObj = new CakeRequest();
$request += array(array(), array());
$request[0] += array('controller' => false, 'action' => false, 'plugin' => null);
$requestObj->addParams($request[0])->addPaths($request[1]);
self::$_requests[] = $requestObj;
}
}
示例13: setUp
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$request = new CakeRequest('posts/index', false);
$request->addParams(array('controller' => 'posts', 'action' => 'index'));
$this->Controller = new SecurityTestController($request);
$this->Controller->Components->init($this->Controller);
$this->Controller->Security = $this->Controller->TestSecurity;
$this->Controller->Security->blackHoleCallback = 'fail';
$this->Security = $this->Controller->Security;
$this->Security->csrfCheck = false;
Configure::write('Security.salt', 'foo!');
}
示例14: testIgnoreRequests
public function testIgnoreRequests()
{
$ignored = Configure::read('NewRelic.ignoreRoutes');
Configure::write('NewRelic.ignoreRoutes', array('/admin/:controller/:action/*', '/:controller/edit/*', '/new_relic_user_test/:action/5'));
$testSucceed = array('/new_relic_test/index', '/new_relic_user_test/view/3');
foreach ($testSucceed as $testUrl) {
$filter = $this->_getNewRelicMock();
$filter->expects($this->once())->method('hasNewRelic')->will($this->returnValue(true));
$filter->expects($this->never())->method('ignoreTransaction');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
$request = new CakeRequest($testUrl);
$request->addParams(Router::parse($testUrl));
$event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
$this->assertTrue($filter->beforeDispatch($event));
$this->assertFalse($event->isStopped());
}
$testFail = array('/admin/new_relic_test/index', '/new_relic_user_test/edit', '/new_relic_user_test/edit/3', '/new_relic_user_test/view/5');
foreach ($testFail as $testUrl) {
$filter = $this->_getNewRelicMock();
$filter->expects($this->once())->method('hasNewRelic')->will($this->returnValue(true));
$filter->expects($this->once())->method('ignoreTransaction');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
$request = new CakeRequest($testUrl);
$request->addParams(Router::parse($testUrl));
$event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
$this->assertTrue($filter->beforeDispatch($event));
$this->assertFalse($event->isStopped());
}
Configure::write('NewRelic.ignoreRoutes', $ignored);
}
示例15: testAddParams
/**
* test addParams() method
*
* @return void
*/
function testAddParams()
{
$request = new CakeRequest('some/path');
$request->params = array('controller' => 'posts', 'action' => 'view');
$result = $request->addParams(array('plugin' => null, 'action' => 'index'));
$this->assertIdentical($result, $request, 'Method did not return itself. %s');
$this->assertEqual($request->controller, 'posts');
$this->assertEqual($request->action, 'index');
$this->assertEqual($request->plugin, null);
}