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

Problems with native class ArrayAccess as Interface #1447

Open
jg-development opened this issue Sep 4, 2024 · 3 comments
Open

Problems with native class ArrayAccess as Interface #1447

jg-development opened this issue Sep 4, 2024 · 3 comments

Comments

@jg-development
Copy link

When I try to reflect a class with arrayaccess interface it does not work:
https://github.com/docusign/docusign-esign-php-client/blob/master/src/Model/AccessCodeFormat.php

Roave\BetterReflection\Reflection\ReflectionClass "ArrayAccess" could not be found in the located source

@kukulich
Copy link
Collaborator

kukulich commented Sep 4, 2024

How do you set up BetterReflection?

@jg-development
Copy link
Author

Cannot show you everything, but it was like this:

    public const string OLD_NAMESPACE = 'DocuSign\eSign\Model';

    public const string NEW_NAMESPACE = 'DocusignEsignatureClient\Structs';



        $finder
            ->in(__DIR__ . '/../../vendor/docusign/esign-client/src/Model')
            ->files()
            ->name('*.php')
            ->notName('*Interface.php')
            ->sortByName(true);

        $iterator = $finder->getIterator();
        $iterator->rewind();

        foreach ($iterator as $modelFile) {
            $classLoader = require __DIR__ . '/../../vendor/autoload.php';

            $astLocator = (new BetterReflection())->astLocator();
            $reflector = new DefaultReflector(new ComposerSourceLocator($classLoader, $astLocator));
            $class = $reflector->reflectClass(self::OLD_NAMESPACE . '\\' . $modelFile->getFilenameWithoutExtension());

            /** @var ReflectionProperty $swaggerTypeProperty */
            $swaggerTypeProperty = $class->getProperty('swaggerTypes');

            $swaggerTypes = $swaggerTypeProperty->getDefaultValue();

            $class = new ClassType($modelFile->getFilenameWithoutExtension());

            $namespace = new PhpNamespace(self::NEW_NAMESPACE);
            $namespace->add($class);
            $namespace->addUse(SerializedName::class);
    }

@Ocramius
Copy link
Member

I think the composer source locator is not sufficient there: needs to be composed together with an internal classes source locator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants