Java Shell Other
Latest commit 7882fa6 Mar 26, 2017 @Haehnchen committed on GitHub Merge pull request #87 from Koc/patch-2
Add FOSRest alias

README.md

IntelliJ IDEA / PhpStorm PHP Annotations

Build Status Version Downloads Downloads last month Donate to this project using Paypal

Provides PHP annotation support for PhpStorm / IntelliJ IDEA and references for "Code > Optimize Imports" action. Code extraction of Symfony Plugin

Key Value
Plugin url https://plugins.jetbrains.com/plugin/7320
Id de.espend.idea.php.annotation
Changelog CHANGELOG

Install

  • Download plugin or install directly out of PhpStorm
  • Force file reindex if necessary with: File -> Invalidate Cache

Versions

  • 4.x: PhpStorm 2016.1.2+
  • 3.x: PhpStorm 2016.1
  • 2.x: PhpStorm9
  • 1.x: PhpStorm8

Settings

Languages & Framework > PHP > Annotations

Round brackets

/**
 * @Foo<caret>()
 * @Foo<caret>
 */
class NotBlank extends Constraint {}

Use / Import alias

Languages & Framework > PHP > Annotations -> Use Alias


use Doctrine\ORM\Mapping as ORM;

/**
 * @Id() -> @ORM\Id()
 */
class Foo {}

Annotation Class Detection

  • Every class with @Annotation inside class doc block is detected on file indexing
  • Annotation Properties on property names
  • Property value types
  • @ENUM Tags
/**
 * @Annotation
 */
class NotBlank extends Constraint {
    public $message = 'This value should not be blank.';
    public $groups = array();

    /**
     * @var Boolean
     */
    public $option = false;

    /**
     *
     * @Enum({"AUTO", "SEQUENCE", "TABLE", "IDENTITY", "NONE", "UUID", "CUSTOM"})
     */
    public $strategy = 'AUTO';

    /**
     * @var array<string>
     */
    public $cascade;

}

Annotation Target Detection

@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.';
}

Extension Points

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"/>
</extensionPoints>

Usage

<extensions defaultExtensionNs="de.espend.idea.php.annotation">
  <PhpAnnotationExtension implementation="de.espend.idea.php.annotation.completion.PhpAnnotationTypeCompletionProvider"/>
</extensions>

Completion confidence

Annoying pressing completion shortcut? Plugin provides a nice completion confidence to open completion popover on several conditions

/**
 * @<caret>
 * <caret>
 */

Static values

    /**
     * @DI\Observe(SomethingEvents::PRE_UPDATE)
     */

Doctrine

ORM: Property generator

class Foo {
    public $id<caret>;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    public $id<caret>;
}

ORM: class entity generator

/**
 * @ORM\Entity(repositoryClass="Foo")
 * @ORM\Table(name="bike")
 */
class Foo { }

ORM: repository class generator / intention

/**
 * @ORM\Entity(repositoryClass="UnknownClass")
 */
class Foo { }
/**
 * @ORM\Entity<caret>
 */
class Foo { }

ORM: repository class completion

/**
 * @ORM\Entity(repositoryClass="<caret>")
 */

PHP Toolbox

Provides integration for PHP Toolbox

Default and property values

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"
    }
  ],
}

Property array values

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"
        }
      ]
    }
  ]
}