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

Document default values in annotations #222

Open
apfelbox opened this issue Sep 11, 2018 · 2 comments
Open

Document default values in annotations #222

apfelbox opened this issue Sep 11, 2018 · 2 comments

Comments

@apfelbox
Copy link

apfelbox commented Sep 11, 2018

Hi,

I have found nothing in the documentation (and no test, but didn't search for too long).

Are there some docs about annotations that I can use without explicitly naming the parameters?
I guess it just injects an array with the key "value" but I am not to sure.

For reference, I mean code like this:

/**
 * @SomeAnnot("ohai")
 */

How is this unnamed parameter injected? It would be great if we could add a note about that on https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html

@Ocramius
Copy link
Member

I think it is called value and passed to the constructor of your annotation as such, but not sure about it either: would indeed need test and documentation additions.

@Majkl578
Copy link
Contributor

There is a test here:

public function testDefaultValueAnnotations()
{
$parser = $this->createTestParser();
// Array as first value
$result = $parser->parse('@Name({"key1"="value1"})');
$annot = $result[0];
self::assertInstanceOf(Name::class, $annot);
self::assertInternalType('array', $annot->value);
self::assertEquals('value1', $annot->value['key1']);
// Array as first value and additional values
$result = $parser->parse('@Name({"key1"="value1"}, foo="bar")');
$annot = $result[0];
self::assertInstanceOf(Name::class, $annot);
self::assertInternalType('array', $annot->value);
self::assertEquals('value1', $annot->value['key1']);
self::assertEquals('bar', $annot->foo);
}

But I agree it's a bit magic, maybe something to re-think in 2.0 (i.e. explciitly marking specific property as @Default).

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

No branches or pull requests

3 participants