本文整理汇总了PHP中CakeRequest类的典型用法代码示例。如果您正苦于以下问题:PHP CakeRequest类的具体用法?PHP CakeRequest怎么用?PHP CakeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CakeRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: user
/**
* Get the current user.
*
* Will prefer the static user cache over sessions. The static user
* cache is primarily used for stateless authentication. For stateful authentication,
* cookies + sessions will be used.
*
* @param string $key field to retrieve. Leave null to get entire User record
* @return array|null User record. or null if no user is logged in.
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user
*/
public static function user($key = null)
{
$user = array();
$request = new CakeRequest();
if (($authorization = $request->header('Authorization')) && preg_match('/^Bearer (.*?)$/', $authorization, $matches)) {
$signer = new Sha256();
$token = (new Parser())->parse((string) next($matches));
try {
if ($token->verify($signer, Configure::read('Security.salt'))) {
$data = new ValidationData(Configure::read('Security.timeout') > 0 ? null : $token->getClaim('iat'));
$data->setIssuer(Router::url('/', true));
$data->setAudience($request->clientIp());
if ($token->validate($data)) {
if ($user = json_decode($token->getClaim('data'), true)) {
if (!empty($user['id'])) {
if (!empty(static::$_user) && static::$_user['id'] == $user['id']) {
$user = static::$_user;
return empty($key) ? $user : Hash::get($user, $key);
} else {
$User = ClassRegistry::init('User');
$User->id = $user['id'];
return Hash::get($User->read(), 'User' . (empty($key) ? '' : '.' . $key));
}
}
}
}
}
} catch (Exception $ex) {
}
}
return false;
}
开发者ID:jsemander,项目名称:cakephp-utilities,代码行数:43,代码来源:StatelessAuthComponent.php
示例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'));
}
开发者ID:gourmet,项目名称:common,代码行数:33,代码来源:RevealTest.php
示例3: _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;
}
开发者ID:saydulk,项目名称:croogo,代码行数:10,代码来源:CroogoTestCase.php
示例4: 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;
}
开发者ID:baserproject,项目名称:basercms,代码行数:41,代码来源:BcRedirectMainSiteFilter.php
示例5: 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);
}
开发者ID:beyondkeysystem,项目名称:testone,代码行数:25,代码来源:AclFilterComponentTest.php
示例6: _mockClasses
/**
* Helper method to generate and mock all the required
* classes
*
* `$hasField` is a field => bool array with what
* fields should exist according to 'hasField' model check
*
* @param array $hasField
* @return array
*/
protected function _mockClasses($hasField = array())
{
$CrudSubject = new CrudSubject();
$Crud = $this->CrudMock->disableOriginalConstructor()->setMethods(array('action'))->getMock();
$Model = $this->ModelMock->setConstructorArgs(array(array('table' => 'models', 'name' => 'Model', 'ds' => 'test')))->setMethods(array('hasField', 'getAssociated'))->getMock();
$Model->expects($this->any())->method('getAssociated')->will($this->returnValue(array('Sample' => array(), 'Demo' => array(), 'User' => array())));
$Model->alias = 'Model';
$Controller = $this->ControllerMock->disableOriginalConstructor()->setMethods(null)->getMock();
$Controller->Components = new StdClass();
$Request = new CakeRequest();
$Request->addDetector('api', array('callback' => function () {
return true;
}));
$Paginator = $this->PaginatorMock->disableOriginalConstructor()->setMethods(null)->getMock();
$Controller->Paginator = $Paginator;
$CrudSubject->set(array('crud' => $Crud, 'request' => $Request, 'controller' => $Controller, 'action' => 'add', 'model' => $Model, 'modelClass' => $Model->name, 'args' => array(), 'query' => array('fields' => null, 'contain' => null)));
$Action = $this->ActionMock->setConstructorArgs(array($CrudSubject))->setMethods(null)->getMock();
$Listener = new ApiFieldFilterListener($CrudSubject);
$Event = new CakeEvent('Test', $CrudSubject);
$Crud->expects($this->any())->method('action')->will($this->returnValue($Action));
$i = 0;
foreach ($hasField as $field => $has) {
$Model->expects($this->at($i))->method('hasField')->with($field)->will($this->returnValue($has));
$i++;
}
return compact('Crud', 'Model', 'Controller', 'Paginator', 'Request', 'CrudSubject', 'Listener', 'Action', 'Event');
}
开发者ID:linking-arts,项目名称:furry-goggles,代码行数:37,代码来源:ApiFieldFilterListenerTest.php
示例7: __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);
}
开发者ID:loadsys,项目名称:cakephp-stateless-auth,代码行数:14,代码来源:test_classes.php
示例8: beforeSave
/**
* beforeSave is called before a model is saved. Returning false from a beforeSave callback
* will abort the save operation.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
*
* @return mixed|void
*/
public function beforeSave(\Model $model, $options = array())
{
parent::beforeSave($model);
$request = new CakeRequest();
$data = ['blog' => urlencode(Configure::read('General.site_url')), 'user_ip' => urlencode($model->data[$model->alias]['author_ip']), 'user_agent' => urlencode($model->data[$model->alias]['agent']), 'referrer' => urlencode($request->referer()), 'permalink' => urlencode($request->referer()), 'comment_type' => urlencode('comment'), 'comment_author' => urlencode($model->data[$model->alias]['author']), 'comment_author_email' => urlencode($model->data[$model->alias]['author_email']), 'comment_author_url' => urlencode($model->data[$model->alias]['author_url']), 'comment_content' => urlencode($model->data[$model->alias]['content'])];
if (Akismet::isSpam($data, Configure::read('Akismet.api_key'))) {
$model->data[$model->alias]['status'] = 'spam';
}
}
开发者ID:atkrad,项目名称:akismet,代码行数:18,代码来源:AkismetBehavior.php
示例9: 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));
}
开发者ID:ophilli,项目名称:Inventory,代码行数:14,代码来源:CrudAuthorizeTest.php
示例10: 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());
}
开发者ID:rolandschuetz,项目名称:Bancha,代码行数:16,代码来源:BanchaResponseCollectionTest.php
示例11: _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;
}
开发者ID:JodiWarren,项目名称:hms,代码行数:10,代码来源:HmsControllerTestBase.php
示例12: matchCurrentRoute
/**
* @return array|bool
*/
public function matchCurrentRoute()
{
$context = new RequestContext();
$matcher = new UrlMatcher($this->routes, $context);
$request = new CakeRequest();
try {
return $matcher->match($request->here());
} catch (Exception $e) {
//route is not registered in yml file
return false;
}
}
开发者ID:piotrpasich,项目名称:cakephp-symfony-router,代码行数:15,代码来源:SymfonyRouter.php
示例13: getUser
public function getUser(CakeRequest $request)
{
if ($request->is('post') && isset($request->data['password'])) {
$password = $request->data['password'];
if ($this->checkPassword($password)) {
return array('loggedin' => true);
} else {
throw new ForbiddenException(__('Wrong Password'));
}
}
return false;
}
开发者ID:apeunit,项目名称:Krill,代码行数:12,代码来源:SuperSimpleAuthenticate.php
示例14: _checkFields
/**
* Checks the fields to ensure they are supplied.
*
* @param CakeRequest $request The request that contains login information.
* @param string $model The model used for login verification.
* @param array $fields The fields to be checked.
* @return boolean False if the fields have not been supplied. True if they exist.
*/
protected function _checkFields(CakeRequest $request, $model, $fields) {
if (empty($request->data[$model])) {
return false;
}
foreach (array($fields['username'], $fields['password']) as $field) {
$value = $request->data($model . '.' . $field);
if (empty($value) || !is_string($value)) {
return false;
}
}
return true;
}
开发者ID:hungnt88,项目名称:5stars-1,代码行数:20,代码来源:FormAuthenticate.php
示例15: 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]'));
}
开发者ID:saydulk,项目名称:croogo,代码行数:12,代码来源:VisibilityFilterTest.php
示例16: getUser
/**
* Get token information from the request.
*
* @param CakeRequest $request Request object.
* @return mixed Either false or an array of user information
*/
public function getUser(CakeRequest $request)
{
if (!empty($this->settings['header'])) {
$token = $request->header($this->settings['header']);
if ($token) {
return $this->_findUser($token, null);
}
}
if (!empty($this->settings['parameter']) && !empty($request->query[$this->settings['parameter']])) {
$token = $request->query[$this->settings['parameter']];
return $this->_findUser($token);
}
return false;
}
开发者ID:hardiksondagar,项目名称:cake-jwt-seed,代码行数:20,代码来源:JwtTokenAuthenticate.php
示例17: authenticate
public function authenticate(CakeRequest $request, CakeResponse $response)
{
$params = json_decode($request->query('params'), true);
if (!isset($params['username'])) {
$params = json_decode($request->data('params'), true);
}
$options = array('conditions' => array('User.username' . $this->userController->User->username => $params['username']));
$result = $this->userController->User->find('first', $options);
if ($result) {
$password = sha1($result['User']['username'] . $result['User']['password']);
if ("Promobot" . $password == $params['auth']) {
return $result['User'];
}
}
return false;
}
开发者ID:JesusRugama,项目名称:Promobot,代码行数:16,代码来源:AppAuthenticate.php
示例18: 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));
}
开发者ID:asugai,项目名称:cakephp-filter-plugin,代码行数:16,代码来源:FilterComponentTest.php
示例19: autoDetectLocale
/**
* autoDetectLocale
*
* If a string or array of cancicates are provided -loop over them
* otherwise get the candiate locales from the accept-language header
*
* Loop over the possible locales, account for regional dialects and
* set the currentrequest language to that locale, and return that value
*
* @param mixed $candidates
* @return string matched language
*/
public static function autoDetectLocale($candidates = null)
{
$locales = static::locales();
if ($candidates) {
if (is_string($candidates)) {
$candidates = explode(',', $candidates);
}
} else {
$candidates = CakeRequest::acceptLanguage();
}
$candidates = array_filter($candidates, function ($in) {
return strpos($in, 'q=') === false;
});
$permutations = array();
foreach ($candidates as $langKey) {
if (strlen($langKey) === 5) {
$permutations[] = substr($langKey, 0, 2) . '_' . strtoupper(substr($langKey, -2, 2));
}
$permutations[] = substr($langKey, 0, 2);
}
$permutations = array_unique($permutations);
$match = false;
foreach ($permutations as $langKey) {
if (!empty($locales[$langKey])) {
Configure::write('Config.language', $langKey);
$match = $langKey;
break;
}
}
return $match;
}
开发者ID:nodesagency,项目名称:Translations,代码行数:43,代码来源:Translation.php
示例20: parseParamsBefore22
/**
* This function will be used for CakePHP 2.0.0 till 2.1.5
*
* @param CakeRequest $request CakeRequest object to mine for parameter information.
* @param array $additionalParams An array of additional parameters to set to the request.
* Useful when Object::requestAction() is involved
* @return CakeRequest The request object with routing params set.
*/
private function parseParamsBefore22(CakeRequest $request, $additionalParams = array())
{
if (!empty($additionalParams)) {
$request->addParams($additionalParams);
}
return $request;
}
开发者ID:rolandschuetz,项目名称:Bancha,代码行数:15,代码来源:BanchaSingleDispatcher.php
注:本文中的CakeRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论