Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Class existence resource #20121

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

Merged
merged 2 commits into from
Oct 5, 2016
Merged

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Oct 1, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets see #20094
License MIT
Doc PR n/a

namespace Symfony\Component\Config\Resource;

/**
* ClassExistenceResource represents a class availability.
Copy link
Member

Choose a reason for hiding this comment

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

Let's replace availability with existence, to be consistent with the class name and the class_exists function name.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

EOF
);

$this->assertFalse($res->isFresh(time()));
Copy link
Member

Choose a reason for hiding this comment

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

Afaik, this should be assertTrue. In table form (horizontal: current state, vertical: stored state)

Class exists Class does not exists
Class exists Not fresh Fresh
Class does not exists Fresh Not fresh

Copy link
Member Author

Choose a reason for hiding this comment

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

The freshness is all about the state change. The resource is fresh if there is no change in class existence, so no need to refresh the cache. Not fresh means that the cache must be recalculated, so when the state changes. So, the table should be:

Class exists Class does not exists
Class exists Fresh Not fresh
Class does not exists Not fresh fresh

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry. Completely messed up the definition of "fresh"...

@@ -72,15 +76,18 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.assets')->addTag('twig.extension');
}

if (class_exists('Symfony\Component\Yaml\Parser')) {
$container->addResource(new ClassExistenceResource(YamlParser::class));
if (class_exists(YamlParser::class)) {
Copy link
Member

@javiereguiluz javiereguiluz Oct 2, 2016

Choose a reason for hiding this comment

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

Related to this comment, just asking if we could replace this:

if (class_exists(YamlParser::class)) {
    $container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
}

by this?

if (!class_exists(YamlParser::class)) {
    $container->removeDefinition('twig.extension.yaml');
}

Copy link
Member

Choose a reason for hiding this comment

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

The difference is that if one uses the twig.extension.yaml directly, the proposed version will break.
I think the current approach is a more open thus a better practice, even if in this very case using the extension directly is so unlikely.

@fabpot fabpot force-pushed the class-existence-resource branch from 8d0ff06 to 222b56d Compare October 3, 2016 23:53
@fabpot fabpot merged commit 222b56d into symfony:master Oct 5, 2016
fabpot added a commit that referenced this pull request Oct 5, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

Class existence resource

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | see #20094
| License       | MIT
| Doc PR        | n/a

Commits
-------

222b56d [TwigBundle] added support for ClassExistenceResource when relevant
d98eb7b [Config] added ClassExistenceResource
fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this pull request Oct 5, 2016
This PR was merged into the 4.0.x-dev branch.

Discussion
----------

added support for ClassExistenceResource

depends on symfony/symfony#20121

Commits
-------

a1f987d added support for ClassExistenceResource
public function __construct($resource)
{
$this->resource = $resource;
$this->exists = class_exists($resource);
Copy link
Member

Choose a reason for hiding this comment

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

we should use class_exists() || interface_exists() || trait_exists() to make it usable for interfaces and traits too

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

Successfully merging this pull request may close these issues.

6 participants