Giter Site home page Giter Site logo

doctrine / reflection Goto Github PK

View Code? Open in Web Editor NEW
3.0K 15.0 20.0 552 KB

The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection API that comes with PHP. It allows you to get the reflection information about classes, methods and properties statically.

Home Page: https://www.doctrine-project.org/projects/reflection.html

License: MIT License

PHP 100.00%
reflection

reflection's Introduction

⚠ This package is abandoned, consider migrating to alternatives, such as roave/better-reflection. Features that are still useful to Doctrine have been moved to doctrine/persistence

Doctrine Reflection

Build Status Code Coverage

The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection functionality that comes with PHP. It allows you to get the reflection information about classes, methods and properties statically.

More resources:

reflection's People

Contributors

alcaeus avatar alexpott avatar beberlei avatar benmorel avatar boesing avatar carusogabriel avatar chx avatar dunglas avatar fruit avatar greg0ire avatar guilhermeblanco avatar hobodave avatar jeroendedauw avatar jwage avatar lcobucci avatar majkl578 avatar malarzm avatar mikesimonson avatar nicwortel avatar ocramius avatar ondrejmirtes avatar ostrolucky avatar pgrimaud avatar racheldomingo avatar romanb avatar schmittjoh avatar seldaek avatar senseexception avatar sspat avatar stof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reflection's Issues

Missing error check after regex

An error check is missing after doing a preg_match() here. The code just ignores any errors, such as exceeding pcre.backtrack_limit. This is also true for the current master branch.
Found the missing error check when getting this Drupal error.

Something like this should be added after. Stolen from the Symfony YAML parser.

if (preg_match("/\A.*^\s*((abstract|final)\s+)?class\s+{$this->shortClassName}\s+/sm", $contents, $matches)) {
    $contents = $matches[0];
}
switch (preg_last_error()) {
    case PREG_INTERNAL_ERROR:
        $error = 'Internal PCRE error.';
        break;
    case PREG_BACKTRACK_LIMIT_ERROR:
        $error = 'pcre.backtrack_limit reached.';
        break;
    case PREG_RECURSION_LIMIT_ERROR:
        $error = 'pcre.recursion_limit reached.';
        break;
    case PREG_BAD_UTF8_ERROR:
        $error = 'Malformed UTF-8 data.';
        break;
    case PREG_BAD_UTF8_OFFSET_ERROR:
        $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.';
        break;
    default:
        $error = FALSE;
}

if ($error) throw new \Exception("Wow we did it! $error");

PHP 8.1 compatibility

Deprecated: Return type of Doctrine\Common\Reflection\RuntimePublicReflectionProperty::getValue($object = null) should either be compatible with ReflectionProperty::getValue(?object $object = null): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ./lib/Doctrine/Common/Reflection/RuntimePublicReflectionProperty.php on line 20

Deprecated: Return type of Doctrine\Common\Reflection\RuntimePublicReflectionProperty::setValue($object, $value = null) should either be compatible with ReflectionProperty::setValue(mixed $objectOrValue, mixed $value = ): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ./lib/Doctrine/Common/Reflection/RuntimePublicReflectionProperty.php on line 44

Deprecated: Return type of Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty::getValue($object = null) should either be compatible with ReflectionProperty::getValue(?object $object = null): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ./lib/Doctrine/Common/Reflection/TypedNoDefaultReflectionProperty.php on line 19

Deprecated: Return type of Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty::setValue($object, $value = null) should either be compatible with ReflectionProperty::setValue(mixed $objectOrValue, mixed $value = ): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ./lib/Doctrine/Common/Reflection/TypedNoDefaultReflectionProperty.php on line 32

Tests not passing if run on PHP 7.4 or Windows

Currently the following errors are happening if trying to run the tests in PHP 7.4.
Also some tests are failing if run on Windows.

This is the PHPUnit output:

$ vendor/bin/phpunit
PHPUnit 7.3.5 by Sebastian Bergmann and contributors.

F.FF........E.............................................E.EE.  63 / 124 ( 50%)
...............................................EEE...........   124 / 124 (100%)

Time: 145 ms, Memory: 6.00MB

There were 7 errors:

1) Doctrine\Tests\Common\Reflection\StaticReflectionClassTest::testGetMethod
Declaration of Doctrine\Common\Reflection\StaticReflectionMethod::getClosure($object) should be compatible with ReflectionMethod::getClosure($object = NULL)

C:\work\projects\oss\doctrine-reflection\lib\Doctrine\Common\Reflection\StaticReflectionMethod.php:92
C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionClassTest.php:59

2) Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest::testGetDeclaringClass
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest.php:30

3) Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest::testGetDocComment
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest.php:50

4) Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest::testGetUseStatements
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionMethodTest.php:62

5) Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest::testGetDeclaringClass
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest.php:30

6) Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest::testGetDocComment
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest.php:41

7) Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest::testGetUseStatements
Function ReflectionType::__toString() is deprecated

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\StaticReflectionPropertyTest.php:53

--

There were 3 failures:

1) Doctrine\Tests\Common\Reflection\Psr0FindFileTest::testFindFile
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection/NoParent.php'
+'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\NoParent.php'

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\Psr0FindFileTest.php:20

2) Doctrine\Tests\Common\Reflection\Psr0FindFileTest::testFindFileWithLeadingNamespaceSeparator
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection/NoParent.php'
+'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\NoParent.php'

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\Psr0FindFileTest.php:32

3) Doctrine\Tests\Common\Reflection\Psr0FindFileTest::testFindFileFromPearLikeClassName
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection/NoParent.php'
+'C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\NoParent.php'

C:\work\projects\oss\doctrine-reflection\tests\Doctrine\Tests\Common\Reflection\Psr0FindFileTest.php:39

ERRORS!
Tests: 124, Assertions: 218, Errors: 7, Failures: 3.

Trying to access array offset on value of type null in Doctrine\Common\Reflection\StaticReflectionParser->parse

I'm getting the following notice running version 1.1.0:

Notice: Trying to access array offset on value of type null in Doctrine\Common\Reflection\StaticReflectionParser->parse() (line 192).

First part of the stack trace:

Doctrine\Common\Reflection\StaticReflectionParser->parse() (Line: 303)
Doctrine\Common\Reflection\StaticReflectionParser->getDocComment() (Line: 35)
Doctrine\Common\Reflection\StaticReflectionClass->getDocComment() (Line: 101)
Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)

Bug when deserializing ?string 7.4-hinted properties.

Hi, anyone seeing a weird bug after composer update today?

If my column in DB is a nullable string and set to null, Doctrine does not hydrate the property with null but “ignores” the property altogether, which results in
Typed property ... must not be accessed before initialization
Started happening today after composer update.

dbb
See element 0 of array - it is missing event property altogether.
It did not happen yesterday, yesterday it was hydrated normally null as you would expect.

@beberlei

DocComment for the main class is incorrect when an anonymous class is used inside.

Example of the class:

<?php

namespace MyNameSpace;

/**
 * Class MyClass.
 *
 * @Annotation(
 *   id = "my_id"
 * )
 */
class MyClass {

  /**
   * {@inheritdoc}
   */
  public function initializeIterator() {


    $array = [
      ['name' => 'Jonathan','id' => '5'],
      ['name' => 'Abdul' ,'id' => '22'],
    ];

    $object = new \ArrayObject($array);

    $filter_iterator = new class ($object->getIterator()) extends \FilterIterator {
      public function accept() {
        $user = $this->getInnerIterator()->current();
        if( strcasecmp($user['name'],'abdul') == 0) {
          return false;
        }
        return true;
      }
    };

    return $filter_iterator;

  }

}

Then I try to get DocComment by next code:

$class = 'MyNameSpace\MyClass';

$finder = new \Doctrine\Common\Reflection\Psr0FindFile(['MyNameSpace' => ['my_folder']]);
$parser = new \Doctrine\Common\Reflection\StaticReflectionParser($class, $finder, FALSE);

$doctrine_doc = $parser->getDocComment();

expected result:

/**
 * Class MyClass.
 *
 * @Annotation(
 *   id = "my_id"
 * )
 */

actual result: empty string.

After debugging I found out that the parse overrides DocComment for the main class by DocComment of an anonymous class which is empty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.