Movatterモバイル変換


[0]ホーム

URL:


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

Added a build method to the kernel to replace Bundle::build()#20107

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromlinaori:feature/appbundle-less
Feb 22, 2017
Merged

Added a build method to the kernel to replace Bundle::build()#20107

fabpot merged 1 commit intosymfony:masterfromlinaori:feature/appbundle-less
Feb 22, 2017

Conversation

@linaori
Copy link
Contributor

@linaorilinaori commentedSep 30, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#20099
LicenseMIT
Doc PR~

Adds a DX method to make it easier to omit using an AppBundle in your application.

Old situation

// src/AppBundle.phpclass AppBundleextends Bundle{publicfunctionbuild(ContainerBuilder$container)    {$container->addCompilerPass(newSomeCompilerPass());$container->addCompilerPass(newAnotherCompilerPass());$container->addCompilerPass(newYetAnotherCompilerPass());    }}// src/DependencyInjection/AppExtension.phpclass AppExtensionextends Extension{publicfunctionload(array$config,ContainerBuilder$container)    {$binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');$snappyConfig = ['pdf' => ['binary' =>realpath($binary)]];$container->prependExtensionConfig('knp_snappy',$snappyConfig);    }}

New situation

// rm src/AppBundle.php// rm src/DependencyInjection/AppExtension.php// app/AppKernel.phpclass AppKernelextends Kernel{protectedfunctionbuild(ContainerBuilder$container)    {$binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');$snappyConfig = ['pdf' => ['binary' =>realpath($binary)]];$container->prependExtensionConfig('knp_snappy',$snappyConfig);$container->addCompilerPass(newSomeCompilerPass());$container->addCompilerPass(newAnotherCompilerPass());$container->addCompilerPass(newYetAnotherCompilerPass());    }}

Still missing tests, wondering if worth adding in this state first.

akomm, theofidry, chalasr, garyttierney, Taluu, maennchen, stloyd, ogizanagi, apfelbox, maximecolin, and 13 more reacted with thumbs up emojiHeahDude, theofidry, Taluu, chalasr, yceruto, maximecolin, Guikingone, mnapoli, Pierstoval, Shine-neko, and 2 more reacted with heart emoji
@akomm
Copy link

The less often you need to create an Extension in AppBundle, the better.

@fabpot
Copy link
Member

I like this a lot!

sstok and docteurklein reacted with heart emoji

* If a class contains annotations, add it to getAnnotatedClassesToCompile()instead.
*
* @return string[]
*/
Copy link
Contributor

@GuilhemNGuilhemNSep 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

Is it still worth it when using php7 ?

Choose a reason for hiding this comment

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

I'm planning to verify this soon. Yet this PR is right adding it: it's just moving existing things around, and we still support php 5.
If php7 makes this unnecessary, then the whole inline system could be deprecated.
To be proven first, and not in this PR imho.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@Ener-Getick if not, we could always patch it to only create and load this in php 5

Copy link
Contributor

Choose a reason for hiding this comment

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

This is mostly for new apps (which should use 7.0) so imo it doesn't make sense to allow that if that's not worth it in 7.0 but of course as@nicolas-grekas said, at worst we'll only have to deprecate it later.

@backbone87
Copy link
Contributor

backbone87 commentedSep 30, 2016
edited
Loading

Would it be worth to let the Kernel itself be a container extension?

@linaori
Copy link
ContributorAuthor

*/
publicfunctionprocess(ContainerBuilder$container)
{
$classes =array();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about$classes = $this->kernel->getClassesToCompile(); and drop all foreaches below.. (ie. is replacing thearray_merge withforeach really needed for performance?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ideally I'd just append everything to 1 big array and then doarray_merge([], ...$classes), but 5.5 doesn't support that

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Actually, assigning everything from the kernel as defaults isn't a bad idea

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly. The order seems more logical imo.

file_put_contents($this->getCacheDir().'/annotations.map',sprintf('<?php return %s;',var_export($annotatedClasses,true)));
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Returns (same for the other method below)


/**
* Return a list of classes to be cached away when the container is build.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this is worth a duplicated extra comment, the API looks explicit enough

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its worth mentioning it here, although i would word it like so "Do not add classes that contain annotations, use ... instead"

* Use this method to register compiler passes and manipulate the container during the building process.
*
* @param ContainerBuilder $container
*/
Copy link
Member

@javiereguiluzjaviereguiluzOct 1, 2016
edited
Loading

Choose a reason for hiding this comment

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

I don't like the name of this method. According to theSymfony naming conventions I think this should be calledbuildContainer() because we are not building the kernel, which is what theKernel class is about.

HeahDude, ro0NL, and derrabus reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good point

Copy link
Contributor

@ro0NLro0NLOct 1, 2016
edited
Loading

Choose a reason for hiding this comment

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

So isntKernel::buildContainer the methodBundle::build tends to be, ie.. do we still need that? Should it beBundle::buildContainer?

If you go bundles, you probably (should) go extensions anyway.

If you want a more simple bundle i'd prefer the approach from#19596.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@javiereguiluz buildContainer is already taken

@linaori
Copy link
ContributorAuthor

@tgalopin in#19205 you've added the annotated class cache and in#18533 you've added the class cache warmer. However, the kernel never received a variant of this. What is this for? I noticed that it never loads the annotated classes but it does load the normal class cache. However, there's also a ClassCacheCacheWarmer that does this.@fabpot do you know what the idea behind this is?

I'm wondering if something is broken here.

protectedfunctiondoLoadClassCache($name,$extension)    {if (!$this->booted &&is_file($this->getCacheDir().'/classes.map')) {            ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'),$this->getCacheDir(),$name,$this->debug,false,$extension);        }    }

@linaori
Copy link
ContributorAuthor

Added tests, everything seems to work now.

@nicolas-grekas
Copy link
Member

@iltar the annotated class requires an optimized composer autoloader to work, this maybe why you don't see it working?

@linaori
Copy link
ContributorAuthor

@nicolas-grekas I was wondering why the kerneldoes load the class cache while there's also a class cache warmer, but only a class cache warmer for the annotation variant. It feels like the kernel variant could be removed.

@nicolas-grekas
Copy link
Member

Could be yes, now that the cache warmer should be working as expected in 3.2.
The draw back is that cache warmers aren't always used, but maybe we shouldn't care :)

}

foreach ($extension->getAnnotatedClassesToCompile()as$annotatedClass) {
$annotatedClasses[] =$annotatedClass;
Copy link
Contributor

Choose a reason for hiding this comment

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

why stop usingarray_merge rather than aforeach here ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Basically due to performance. Array merge in loops is slow (at least in php5, haven't benchmarked 7 myself):https://github.com/dseguy/clearPHP/blob/master/rules/no-array_merge-in-loop.md

Copy link
Member

Choose a reason for hiding this comment

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

if this is a performance optimization, you should submit it separately, as it may be worth merging it into 3.2 already.

@linaori
Copy link
ContributorAuthor

Anything still required for this PR?@javiereguiluz had a comment about the name of the method, but the suggested name is already taken.

@ro0NL
Copy link
Contributor

ro0NL commentedOct 22, 2016
edited
Loading

What about afinalize() method as well? Besides it would make sense to renamebuildContainer tocreateContainer, so we can then later usebuild/finalizeContainer (in favor ofbuild/finalize).

That would fix correct naming.

}
}

$this->build($container);
Copy link
Member

Choose a reason for hiding this comment

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

I would put it after bundles, to match the common convention to register your AppBundle last, which would match making AppKernel last when callingbuild.

Registering normal compiler passes of the project after the core normal compiler passes is more logical IMO, and would limit the need to use priority overrides.

}
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

technically, you can already achieve this by overridingKernel::buildContainer, as long as you take care to start by calling the parent method.

}

foreach ($extension->getAnnotatedClassesToCompile()as$annotatedClass) {
$annotatedClasses[] =$annotatedClass;
Copy link
Member

Choose a reason for hiding this comment

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

if this is a performance optimization, you should submit it separately, as it may be worth merging it into 3.2 already.

@linaori
Copy link
ContributorAuthor

  • Reverted the changes related to the class cache due toConsider deprecating ClassCollectionLoader & co. #20668
  • Decided to keep thebuild() method as is:
    • Deprecated/renaming methods in the kernel was not part of this scope (but I do agree naming could be a bit better now)
    • The Kernelbuild() is exactly the same as the bundlebuild(), which makes it a lot more intuitive and easier to understand how it works
  • Thebuild() method for the kernel is now called last instead of first as mentioned by@stof.

@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 6, 2016
@linaori
Copy link
ContributorAuthor

Status: Needs Review

@linaorilinaori changed the titleAdded build and class cache to kernelAdded a build method to the kernel to replace Bundle::build()Jan 11, 2017
@xabbuh
Copy link
Member

👍

Status: Reviewed

@linaori
Copy link
ContributorAuthor

Failure is unrelated:Symfony\Component\Process\Tests\ProcessTest::testInputStreamWithCallable, PR is merged against the latest master

@fabpot
Copy link
Member

Thank you@iltar.

@fabpotfabpot merged commit62e80fc intosymfony:masterFeb 22, 2017
fabpot added a commit that referenced this pull requestFeb 22, 2017
…build() (iltar)This PR was merged into the 3.3-dev branch.Discussion----------Added a build method to the kernel to replace Bundle::build()| Q | A || --- | --- || Branch? | master || Bug fix? | no || New feature? | yes || BC breaks? | no || Deprecations? | no || Tests pass? | yes || Fixed tickets |#20099 || License | MIT || Doc PR | ~ |Adds a DX method to make it easier to omit using an AppBundle in your application.**Old situation**``` php// src/AppBundle.phpclass AppBundle extends Bundle{    public function build(ContainerBuilder $container)    {        $container->addCompilerPass(new SomeCompilerPass());        $container->addCompilerPass(new AnotherCompilerPass());        $container->addCompilerPass(new YetAnotherCompilerPass());    }}// src/DependencyInjection/AppExtension.phpclass AppExtension extends Extension{    public function load(array $config, ContainerBuilder $container)    {        $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');        $snappyConfig = ['pdf' => ['binary' => realpath($binary)]];        $container->prependExtensionConfig('knp_snappy', $snappyConfig);    }}```**New situation**``` php// rm src/AppBundle.php// rm src/DependencyInjection/AppExtension.php// app/AppKernel.phpclass AppKernel extends Kernel{    protected function build(ContainerBuilder $container)    {        $binary = ExecutableResolver::getPath($container->getParameter('kernel.root_dir').'/../');        $snappyConfig = ['pdf' => ['binary' => realpath($binary)]];        $container->prependExtensionConfig('knp_snappy', $snappyConfig);        $container->addCompilerPass(new SomeCompilerPass());        $container->addCompilerPass(new AnotherCompilerPass());        $container->addCompilerPass(new YetAnotherCompilerPass());    }}```Still missing tests, wondering if worth adding in this state first.Commits-------62e80fc Added build and class cache to kernel
@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
@fabpotfabpot mentioned this pull requestMay 1, 2017
@linaorilinaori deleted the feature/appbundle-less branchFebruary 8, 2019 13:38
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

+5 more reviewers

@TaluuTaluuTaluu left review comments

@ro0NLro0NLro0NL left review comments

@backbone87backbone87backbone87 left review comments

@GuilhemNGuilhemNGuilhemN left review comments

@HeahDudeHeahDudeHeahDude requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

13 participants

@linaori@akomm@fabpot@backbone87@nicolas-grekas@ro0NL@xabbuh@javiereguiluz@Taluu@stof@GuilhemN@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp