Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to modify a constructor in an existing class within a namespace #180

Unanswered
tacman asked this question in Q&A
Discussion options

I see how to modify a class: https://github.com/nette/php-generator?tab=readme-ov-file#generating-from-existing-ones

But I'm missing how to modify an entire namespace, and in particular, and struggling how to copy the use statement.

I feel like I'm missing something simple. For example, I want to inject

namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class TestController extends AbstractController
{
}

I want to inject an entity manager

namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
final class TestController extends AbstractController
{
 public function __construct(private EntityManagerInterface $em) {
 }
}

I understand how to create this file with PhpGenerator alone and how to load the class with existing bodies, per the instructions above. But how do I get the PhpNamespace instance, so I can tweak the methods and generate the class with the uses and everything else?

Thanks.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /