Issues

ZF-10398: Adding actions to controller generate sintax errors in controller

Issue Type: Bug Created: 2010-08-30T05:00:04.000+0000 Last Updated: 2012-05-12T03:43:24.000+0000 Status: Closed Fix version(s): Reporter: Caragata Cosmin-Mihail (cosmin0103) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Reflection

Related issues: Attachments: - ZF-10398-tests-and-fix.diff

Description

I have added many actions to a controller . Whenever I have added another action to the controller the code in the actions moves to the right

AND

in the actions where the functions ends with 2 breckets like
public funtion addAction { if (3>4){ } } one brecket is deleted and generates a sintax error .

This happens every time i add an action ! I have tested on several versions.

Example 1 - before adding action

class TestController extends Zend_Controller_Action {

public function init()
{
    require_once (APPLICATION_PATH.'\models\masina.class.php');
    require_once (APPLICATION_PATH.'\models\angajat.class.php');
    require_once (APPLICATION_PATH.'\models\Forms.php');
    require_once (APPLICATION_PATH.'\models\Test1.php');
    require_once (APPLICATION_PATH.'\models\statie.class.php');
    require_once (APPLICATION_PATH.'\models\ruta.class.php');
    require_once (APPLICATION_PATH.'\models\traseu.class.php');
}

public function indexAction()
{
    $x = new Application_Model_Test1();
                                    $trasee = $x -> getTraseeActive();
}

public function listruteAction()
{
    $x = new Application_Model_Test1();
                                                            $trasee = $x -> getTraseeActive();

                                                            foreach ($trasee as $t )
                                                                    {

                                                                     $rute [$t['id_ruta'] ] = "ok" ; 

                                                                    }

                                                                    echo "RUTE:<BR>";
                                                                    foreach ($rute as $r => $x )
                                                                       {
                                                                       echo "<a href='listtrasee?ruta=$r' >  $r  </a> <br> ";
        }
}

public function listtraseeAction()
{
    $ruta  =  $this->_request->getQuery("ruta") ;
                                                            echo "Ruta selectata este :  "  . $ruta  . "<BR>" ;

                                                            $x = new Application_Model_Test1();
                                                            $trasee = $x -> getTraseeActive();

                                                            echo "Trasee pentru aceasta ruta : <BR> <br> " ;
                                                            foreach ($trasee as $t )
                                                                {

                                                                if ($t['id_ruta']==$ruta )
                                                                 {              
                                                                    echo "&nbsp ID traseu: <a href='listmasini?id_traseu={$t['id_traseu']}' >" . $t['id_traseu'] ." </a> <BR>";
                                                                    echo "&nbsp Nume complet:" . $t['nume_traseu'] ."<BR>";
                                                                    echo "&nbsp Valabilitate:" . $t['valabilitate'] ."<BR>";
                                                                    echo "-------------------------------------<br>";
                                                                 }

                                                                }

                                                            // action body
}

}


Example 2 - after executing zf create action newaction test(missing action , even more text moving to the right)

class TestController extends Zend_Controller_Action {

public function init()
{
    require_once (APPLICATION_PATH.'\models\masina.class.php');
            require_once (APPLICATION_PATH.'\models\angajat.class.php');
            require_once (APPLICATION_PATH.'\models\Forms.php');
            require_once (APPLICATION_PATH.'\models\Test1.php');
            require_once (APPLICATION_PATH.'\models\statie.class.php');
            require_once (APPLICATION_PATH.'\models\ruta.class.php');
            require_once (APPLICATION_PATH.'\models\traseu.class.php');
}

public function indexAction()
{
    $x = new Application_Model_Test1();
                                            $trasee = $x -> getTraseeActive();
}

public function listruteAction()
{
    $x = new Application_Model_Test1();
                                                                    $trasee = $x -> getTraseeActive();

                                                                    foreach ($trasee as $t )
                                                                            {

                                                                             $rute [$t['id_ruta'] ] = "ok" ; 

                                                                            }

                                                                            echo "RUTE:<BR>";
                                                                            foreach ($rute as $r => $x )
                                                                               {
                                                                               echo "<a href='listtrasee?ruta=$r' >  $r  </a> <br> ";
}

public function listtraseeAction()
{
    $ruta  =  $this->_request->getQuery("ruta") ;
                                                                    echo "Ruta selectata este :  "  . $ruta  . "<BR>" ;

                                                                    $x = new Application_Model_Test1();
                                                                    $trasee = $x -> getTraseeActive();

                                                                    echo "Trasee pentru aceasta ruta : <BR> <br> " ;
                                                                    foreach ($trasee as $t )
                                                                        {

                                                                        if ($t['id_ruta']==$ruta )
                                                                         {              
                                                                            echo "&nbsp ID traseu: <a href='listmasini?id_traseu={$t['id_traseu']}' >" . $t['id_traseu'] ." </a> <BR>";
                                                                            echo "&nbsp Nume complet:" . $t['nume_traseu'] ."<BR>";
                                                                            echo "&nbsp Valabilitate:" . $t['valabilitate'] ."<BR>";
                                                                            echo "-------------------------------------<br>";
                                                                         }

                                                                        }

                                                                    // action body
}

}

Comments

Posted by Konr Ness (konrness) on 2010-09-03T19:28:53.000+0000

I was able to replicate at least part of this problem.

If I start with a simple controller: <?php

class IndexController extends Zend_Controller_Action { public function indexAction() { if (2>3) {} } }

And run the following command:

$ zf.sh create action two Creating an action named two inside controller at /var/www/tmp/application/controllers/IndexController.php Updating project profile '/var/www/tmp/.zfproject.xml' Creating a view script for the two action method at /var/www/tmp/application/views/scripts/index/two.phtml Updating project profile '/var/www/tmp/.zfproject.xml'

My controller now looks like this:

3) { } public function twoAction() { // action body } } Note the parse error in indexAction. Posted by Konr Ness (konrness) on 2010-09-03T20:41:51.000+0000 Found cause is Zend\_Reflection\_Method::getBody(). It does not properly strip the method's opening or closing tags if code exists on the same line as the opening brace, or the code ends in a curly brace. Attached patch including three new unit tests, two of which fail: - testGetBodyReturnsCorrectContentWithCodeOnOpeningBraceLine - testGetBodyReturnsCorrectContentWithClosingBrace I will work on a fix. Posted by Konr Ness (konrness) on 2010-09-03T21:59:38.000+0000 Attached patch that resolves issues with modified code causing parse errors in the following scenarios: - having method with code that exists on same line as method's opening brace - having method with code that ends in curly brace - having method with code on same line as method's closing brace Caragata Cosmin-Mihail, can you apply this patch and see if it resolves the issue? If not, please provide example controller (preferrably smaller than first example) and the command you ran so I can replicate problem? Posted by Caragata Cosmin-Mihail (cosmin0103) on 2010-09-05T23:27:08.000+0000 I have updated Zend/Reflection/Method.php :: getBody to this like you said : public function getBody() { $lines = array\_slice( file($this->getDeclaringClass()->getFileName(), FILE\_IGNORE\_NEW\_LINES), $this->getStartLine(), ($this->getEndLine() - $this->getStartLine()), true ); $firstLine = array_shift($lines); if (trim($firstLine) !== '{') { // if line has method's opening curly brace and more code, remove first curly brace (leaving spaces intact) if (substr(ltrim($firstLine), 0, 1) == '{') { //$firstLine = preg_replace('/{/', '', $firstLine, 1); $firstLine = substr(ltrim($firstLine), 1); } array_unshift($lines, $firstLine); } $lastLine = array_pop($lines); if (trim($lastLine) !== '}') { // if line has code and the method's closing curly brace, remove trailing spaces and last curly brace if (substr(rtrim($lastLine), -1, 1) == '}') { $lastLine = substr(rtrim($lastLine), 0, -1); } array_push($lines, $lastLine); } // just in case we had code on the bracket lines return rtrim(ltrim(implode("\n", $lines), '{'), '}'); return implode("\n", $lines); } } \*Created a new project \*Created a controller named test1 \*Added 2 actions: \*zf create action action1 test1 \*zf create action action2 test1 (I use windows xp btw) \*Edited the first action like this 2) {} } public function action2Action() { // action body } } ?> \*Added 1 more action action3 \*zf craete action action 3 test1 2) { } public function action2Action() { // action body } public function action3Action() { // action body } } ?> \*notice the missing brecket in action1 - problem persists even with the update

*I have re-edited action1 to public function action1Action() { if (1>2) { } // }

  • notice the "//" characters added
  • after running: zf crate action action4 test1 2) { } // } public function action2Action() { // action body } public function action3Action() { // action body } public function action4Action() { // action body } }?>

*notice that the brecket is not missing anymore *in fact , if any characters are in between the 2 breckets the brecket won't be deleted - this happens without the update too *ALTOUGH the ident problem still persists

*My Conclusion: *With or without the update the "missing brecket" problem persists *With or without the update the ident problem persists *Can aviod the missing brecket if ANY characters inserted between the breckets but the ident problem persists(added neutral code like"//" or ";" but any code is ok) *The position of the 2 breckets doesn't matter \ *I have tested this too: public function action1Action() { if (1>2) {} }

*BTW I'm using Xp sp3 , Xampp Lite server , zend 1.10.8

Hope this helps you find the solution .Thank you for the reply.

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-12T03:43:24.000+0000

Duplicate of ZF-9502

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts