Skip to content
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

[BUG]: in Phalcon\Annotations\Adapter\Stream::write() #14515

Closed
phptux opened this issue Nov 6, 2019 · 1 comment
Closed

[BUG]: in Phalcon\Annotations\Adapter\Stream::write() #14515

phptux opened this issue Nov 6, 2019 · 1 comment

Comments

@phptux
Copy link

@phptux phptux commented Nov 6, 2019

Describe the bug
The adapter annotations Stream write the data in a PHP file.
So far so good.
If I run the script and the adapter will load the PHP file I receive the following error:
Call to undefined method Phalcon\Annotations\Reflection::__set_state()

To Reproduce
My class with annotaions:

<?php
/**
 * @RoutePrefix("/admin/files", name="admin-files")
 */
class MyClass {

    /**
     * @Route("/", methods={"GET", "POST"}, name="admin-files")
     */
    public function indexAction()
    {
    }
}

Adapter init and parse the class:

require_once __DIR__ . '/tests/MyClass.php';
$adapter = new \Phalcon\Annotations\Adapter\Stream(['annotationsDir' => __DIR__ . '/cache/']);
$adapter->write('my_class', $adapter->get('MyClass'));

PHP file from the adapter generated:

<?php return Phalcon\Annotations\Reflection::__set_state(array(
   'classAnnotations' => NULL,
   'methodAnnotations' => NULL,
   'propertyAnnotations' => NULL,
   'reflectionData' => 
  array (
    'class' => 
    array (
      0 => 
      array (
        'type' => 300,
        'name' => 'RoutePrefix',
        'arguments' => 
        array (
          0 => 
          array (
            'expr' => 
            array (
              'type' => 303,
              'value' => '/admin/files',
            ),
          ),
          1 => 
          array (
            'expr' => 
            array (
              'type' => 303,
              'value' => 'admin-files',
            ),
            'name' => 'name',
          ),
        ),
        'file' => './tests/MyClass.php',
        'line' => 3,
      ),
    ),
    'methods' => 
    array (
      'indexAction' => 
      array (
        0 => 
        array (
          'type' => 300,
          'name' => 'Route',
          'arguments' => 
          array (
            0 => 
            array (
              'expr' => 
              array (
                'type' => 303,
                'value' => '/',
              ),
            ),
            1 => 
            array (
              'expr' => 
              array (
                'type' => 308,
                'items' => 
                array (
                  0 => 
                  array (
                    'expr' => 
                    array (
                      'type' => 303,
                      'value' => 'GET',
                    ),
                  ),
                  1 => 
                  array (
                    'expr' => 
                    array (
                      'type' => 303,
                      'value' => 'POST',
                    ),
                  ),
                ),
              ),
              'name' => 'methods',
            ),
            2 => 
            array (
              'expr' => 
              array (
                'type' => 303,
                'value' => 'admin-files',
              ),
              'name' => 'name',
            ),
          ),
          'file' => './tests/MyClass.php',
          'line' => 8,
        ),
      ),
    ),
  ),
)); 

Adapter read:

$adapter = new \Phalcon\Annotations\Adapter\Stream(['annotationsDir' => __DIR__ . '/cache/']);
$adapter->read('my_class');

Error message:

PHP Fatal error:  Uncaught Error: Call to undefined method Phalcon\Annotations\Reflection::__set_state() in ./cache/myclass.php:1

Zephir-Code from adapter Phalcon\Annotations\Adapter\Stream:

    /**
     * Writes parsed annotations to files
     */
    public function write(string! key, <Reflection> data) -> void
    {
        string path, code;

        /**
         * Paths must be normalized before be used as keys
         */
        let path = this->annotationsDir . prepare_virtual_path(key, "_") . ".php";

        let code = "<?php return " . var_export(data, true) . "; ";

        if unlikely file_put_contents(path, code) === false {
              throw new Exception("Annotations directory cannot be written");
        }
    }

The PHP function var_export() produce the code.

Details

  • Phalcon version: 4.0.0-rc.2
  • PHP Version: 7.3.11
  • Operating System: Linux Mint
@niden niden added this to To do in 4.0 Release via automation Nov 6, 2019
@niden niden mentioned this issue Nov 6, 2019
4 of 5 tasks complete
@niden niden moved this from To do to In progress in 4.0 Release Nov 6, 2019
niden added a commit that referenced this issue Nov 6, 2019
niden added a commit that referenced this issue Nov 6, 2019
@niden

This comment has been minimized.

Copy link
Member

@niden niden commented Nov 6, 2019

@phptux Thanks for reporting this!

Resolved in the v4 branch #14517

@niden niden closed this Nov 6, 2019
4.0 Release automation moved this from In progress to Done Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.0 Release
  
Done
2 participants
You can’t perform that action at this time.