-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Phalcon\Annotations\Exception' with message 'Scanning error before 'ExitExpression) .. #10155
Comments
Please submit the source code, let test? |
ErrorController.php <?php
namespace Live\Controllers;
use Live\Library\Exception;
class ErrorController extends AbstractController
{
public function notFoundAction()
{
throw new Exception('10003');
}
} Dispatcher $diContainer->set('dispatcher', function () {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('dispatch', new \Live\Plugins\VerifyParamsPlugin());
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Live\Controllers');
return $dispatcher;
}); The verify plugin: <?php
namespace Live\Plugins;
use Live\Library\Exception;
use Live\Library\Validation;
class VerifyParamsPlugin extends \Phalcon\Mvc\User\Plugin
{
public function beforeExecuteRoute($event, $dispatcher)
{
$annotations = $this->annotations->getMethod($dispatcher->getActiveController(), $dispatcher->getActiveMethod());
if (!$annotations->has('ParamsRules')) {
return;
}
$annotation = $annotations->get('ParamsRules');
$needValidationParamRules = [];
foreach ($annotation->getArguments() as $key => $item) {
if (isset($item['required']) && $item['required'] === true) {
if (!$this->request->has($key) && !isset($_FILES[$key])) {
throw new Exception('10002', $key);
}
}
if ($this->request->has($key)) {
if ($this->request->get($key) === '') {
throw new Exception('10002');
}
}
if ($this->request->has($key) || isset($_FILES[$key])) {
$needValidationParamRules[$key] = $item;
}
}
if (!empty($needValidationParamRules)) {
$validation = new Validation($needValidationParamRules);
$messages = $validation->validate(array_merge($_REQUEST, $_FILES));
if (count($messages) != 0) {
throw new Exception('10002');
}
}
}
public function beforeException($event, $dispatcher, $exception)
{
throw $exception;
}
} |
Change to $annotations = $this->annotations->getMethod($dispatcher->getControllerName(), $dispatcher->getActiveMethod()); |
No. Finally I found the error. There is an error in AbstractController, but the error message tells it is the ErrorController. /**
* @SuppressWarnings(PHPMD.ExitExpression)
*/
protected function renderJson(array $data, $statusCode = 200)
{
$this->response->setContentType('application/json', 'UTF-8');
$this->response->setStatusCode($statusCode, self::$httpStatusCodeAndMessages[$statusCode]);
$this->response->setJsonContent($data, JSON_UNESCAPED_SLASHES);
$this->response->send();
exit;
} The annotation I put is to avoid PHPMD warning, but conflicts with phalcon's annotation. So can this be improved?
|
Fixed but can be imporved! |
Does work if you use: |
@andresgutierrez It's right, Add double quotation can fix this question. |
No response from OP |
I have tried all kinds of ways but it just doesn't work.
I want to use annotations but no matter what I put in the doc block, it gives the error: Scanning error before 'ExitExpression
And I have tried php5.5 and php5.6, phalcon 1.3.3 and phalcon 1.3.4. It just doesn't work.
Actually, I used php5.5.12 and phalcon1.3.3 and annotations a couple months ago. But it just doesn't work with all the environment the same.
The following is the backstrace:
Fatal error: Uncaught exception 'Phalcon\Annotations\Exception' with message 'Scanning error before 'ExitExpression) ...' in /vagrant/data/code/phalcon/app/controllers/ErrorController.php on line 7' in /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php:11 Stack trace: #0 [internal function]: Phalcon\Annotations\Reader->parse('Live\Controller...') #1 [internal function]: Phalcon\Annotations\Adapter->get(Object(Live\Controllers\ErrorController)) #2 /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php(11): Phalcon\Annotations\Adapter->getMethod(Object(Live\Controllers\ErrorController), 'notFoundAction') #3 [internal function]: Live\Plugins\VerifyParamsPlugin->beforeExecuteRoute(Object(Phalcon\Events\Event), Object(Phalcon\Mvc\Dispatcher), NULL) #4 [internal function]: Phalcon\Events\Manager->fireQueue(Array, Object(Phalcon\Events\Event)) #5 [internal function]: Phalcon\Events\Manager->fire('dispatch:before...', Object(Phalcon\Mvc\Dispatcher)) #6 [internal function]: Phalcon\Dispatcher->dispatch() #7 /vag in /vagrant/data/code/phalcon/app/plugins/VerifyParamsPlugin.php on line 11
The text was updated successfully, but these errors were encountered: