Provides PHP annotation extended Attribute support and for PhpStorm / IntelliJ IDEA and references for "Code > Optimize Imports" action.
Key | Value |
---|---|
Plugin url | https://plugins.jetbrains.com/plugin/7320 |
Id | de.espend.idea.php.annotation |
Changelog | CHANGELOG |
File -> Invalidate Cache
PHP > Annotations / Attributes
/**
* @Foo<caret>()
* @Foo<caret>
*/
class NotBlank extends Constraint {}
PHP -> Annotations / Attributes -> Use Alias
use Doctrine\ORM\Mapping as ORM;
/**
* @Id() -> @ORM\Id()
* @NotBlank() -> @Assert\NotBlank()
*/
class Foo {}
use Doctrine\ORM\Mapping as ORM;
#[Id] -> #[ORM\Id()]
#[NotBlank] -> #[Assert\NotBlank()]
class Foo {}
LineMarker which provide navigation to annotation class usages
namespace Doctrine\ORM\Mapping;
/**
* @Annotation
*/
final class Entity implements Annotation
{
}
Targeting
/**
* @ORM\Entity()
*/
@Annotation
inside class doc block is detected on file indexing/**
* @Annotation
*/
class NotBlank extends Constraint {
public $message = 'This value should not be blank.';
public $groups = array();
/**
* @var bool|boolean
*/
public $option = false;
/**
*
* @Enum({"AUTO", "SEQUENCE", "TABLE", "IDENTITY", "NONE", "UUID", "CUSTOM"})
*/
public $strategy = 'AUTO';
/**
* @var array<string>
*/
public $cascade;
/**
* @var mixed|foobar|bool
*/
public $mixed;
}
https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html#attribute-types
/**
* @Annotation
*
* @Attributes({
* @Attribute("stringProperty", type = "string"),
* @Attribute("annotProperty", type = "bool"),
* })
*/
*
* @Attributes(
* @Attribute("stringProperty", type = "string"),
* @Attribute("annotProperty", type = "bool"),
* )
*/
class Foobar {}
@Target
is used to attach annotation, if non provided its added to "ALL list"
/**
* @Annotation
* @Target("PROPERTY", "METHOD", "CLASS", "ALL")
*/
class NotBlank extends Constraint {
public $message = 'This value should not be blank.';
}
Plugins provides several extension points, which allows external plugins to provide additional. See some examples on Symfony2 Plugin
Example for extension points.
<extensionPoints>
<extensionPoint name="PhpAnnotationCompletionProvider" interface="de.espend.idea.php.annotation.extension.PhpAnnotationCompletionProvider"/>
<extensionPoint name="PhpAnnotationReferenceProvider" interface="de.espend.idea.php.annotation.extension.PhpAnnotationReferenceProvider"/>
<extensionPoint name="PhpAnnotationDocTagGotoHandler" interface="de.espend.idea.php.annotation.extension.PhpAnnotationDocTagGotoHandler"/>
<extensionPoint name="PhpAnnotationDocTagAnnotator" interface="de.espend.idea.php.annotation.extension.PhpAnnotationDocTagAnnotator"/>
<extensionPoint name="PhpAnnotationGlobalNamespacesLoader" interface="de.espend.idea.php.annotation.extension.PhpAnnotationGlobalNamespacesLoader"/>
<extensionPoint name="PhpAnnotationVirtualProperties" interface="de.espend.idea.php.annotation.extension.PhpAnnotationVirtualProperties"/>
<!-- Custom class alias mapping: "ORM" => "Doctrine\\ORM\\Mapping" -->
<extensionPoint name="PhpAnnotationUseAlias" interface="de.espend.idea.php.annotation.extension.PhpAnnotationUseAlias"/>
</extensionPoints>
Usage
<extensions defaultExtensionNs="de.espend.idea.php.annotation">
<PhpAnnotationExtension implementation="de.espend.idea.php.annotation.completion.PhpAnnotationTypeCompletionProvider"/>
</extensions>
All extensions points providing support to DocBlock and PHP Attributes at the same time.
use Symfony\Component\Validator\Constraints\NotBlank;
#[NotBlank(message: 'An empty file is not allowed.')]
/* @NotBlank({message: "An empty file is not allowed."}) */
#[Template('foo.html.twig')]
/* @Template("foo.html.twig") */
Annoying pressing completion shortcut? Plugin provides a nice completion confidence to open completion popover on several conditions
/**
* @<caret>
* <caret>
*/
/**
* @DI\Observe(SomethingEvents::PRE_UPDATE)
*/
class Foo {
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
public $id<caret>;
}
class Foo {
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
public $id<caret>;
}
#[ORM\Entity(repositoryClass: \Foo::class)]
#[ORM\Table(name: 'bike')]
class Foo { }
/**
* @ORM\Entity(repositoryClass="UnknownClass")
*/
class Foo { }
/**
* @ORM\Entity<caret>
*/
class Foo { }
/**
* @ORM\Entity(repositoryClass="<caret>")
*/
Provides integration for PHP Toolbox
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("<caret>")
* @Route(condition="<caret>")
*/
{
"registrar":[
{
"signatures":[
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"type": "annotation"
},
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"field": "condition",
"type": "annotation"
}
],
"provider":"foo",
"language":"php"
}
],
}
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(methods={"<caret>"})
*/
{
"registrar":[
{
"language":"php",
"provider":"methods",
"signatures":[
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"type": "annotation_array",
"field": "methods"
}
]
}
],
"providers": [
{
"name": "methods",
"items":[
{
"lookup_string": "POST"
}
]
}
]
}