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

Generate Access Interceptor Proxy #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Generate Access Interceptor Proxy #43

wants to merge 4 commits into from

Conversation

kletord
Copy link
Contributor

@kletord kletord commented Mar 25, 2024

Time to open this PR.

Main change: remove the value holder proxy to create an extended class with the interceptor.

This fix some bug and limitation and add another bunch of limitation.

Removed limitations:

  1. Inner object method calls respected annotations behavior
  2. protected method can be annotated

New limitations:

  1. Unable to proxify a factory service definition inside Symfony

Also this PR add a few errors when an impossible operation is asked and add a cache warmer to generate proxies.

I kept the term proxy but is not a proxy anymore ;-)

@kletord kletord requested a review from sidux March 25, 2024 09:30
Copy link

Issued by Coverage Checker:

public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = [])
{
if (!\array_key_exists('methods', $proxyOptions)) {
throw new \InvalidArgumentException(sprintf('Generator %s needs a methods proxyOptions', __CLASS__));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new \InvalidArgumentException(sprintf('Generator %s needs a methods proxyOptions', __CLASS__));
throw new \InvalidArgumentException(sprintf('Generator %s needs a property "methods" in proxyOptions', __CLASS__));

also I'm not sure what you meant with this errors, that the array proxyOptions must have a key 'methods' in it or if the key 'methods' doesn't exist in the array, the Generator class that extends this one must have a method "getProxyOptions()" or something similare ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxyOptions must have a "methods" key

$factoryDefinition->setTags($definition->getTags());

if ($definition->getFactory() !== null) {
$this->compiler->log($this, "Service {$taggedServiceName} is not compatible with service proxy");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make an error

{
foreach ($this->proxies as $proxy) {
if ($proxy instanceof LazyLoadingInterface && !$proxy->isProxyInitialized()) {
$proxy->initializeProxy();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add continue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is LazyLoadingInterface doesn't exist

{
$instanceRef = new \ReflectionObject($object);
$methods = $instanceRef->getMethods(\ReflectionMethod::IS_PUBLIC);
$instanceRef = new \ReflectionClass($class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although scanning all methods of a class permits us to throw errors on decorated private methods, the cost of loading annotation for each method maybe high in dev env

@kletord kletord force-pushed the warmp branch 2 times, most recently from a1e73ed to 48b6ea4 Compare April 15, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants