Phex extends the PHP support provided by Sublime Text 3. It adds additional snippets (PSR-comptabile), extended syntax highlighting and useful commands. Currently there is no possibility to extend the PHP.tmlanguage, therefore this is a replacement instead of an addition.
First you have to disable the default PHP package in your preferences:
{
...
"ignored_packages": [ "PHP" ],
...
}
Then navigate into your Packages directory and clone this repository:
$ git clone https://github.com/florianeckerstorfer/sublime-phex phex
Phex contains some commands to make it easier for you to work with PHP.
You can find videos of every command in better quality on the Phex website.
The Create Class command allows you to create a new PHP class. This currently only works if you are working in a project. By default the class is created based on the project root folder and if there is a src folder in your project root this will be used as base. You can prefix the class with ~ to create the class in the currently active directory, that is, in the directory of the open file.
Phex's Create Class command supports PSR-4, except when using relative names (~ operator). Suppose the following composer.json exists in the project root directory:
{
"autoload": {
"psr-4": {
"Phex\\": "src"
}
}
}Invoking the Create Class command with Phex\Foo\Bar creates a class with the following properties:
- Class name:
Bar - Namespace:
Phex\Foo\Bar - Filename:
src/Foo/Bar.php
Works like the Create Class command, but creates an interface instead of a class.
The Insert Class Name command opens a fuzzy search panel allowing you to select a class and insertes the selected class into the view. This command also works outside of the PHP scope and therefore helps you when writing PHPDoc or other documentation files.
The Insert Namespace command inserts the namespace statement of the active file.
I recommend setting up a keyboard shortcut, for example, Super+Alt+n. You can do this by going to the Preferences menu and selecting Key Bindings - User. Insert the following snippet:
[
// Other key bindings
{
"keys": ["super+alt+n"], "command": "phex_insert_namespace"
}
]The Create Property command inserts the code for a property and the corresponding setter and getter into the active document. Phex also creates the appropriate PHPDoc for property, setter and getter. You can invoke the command and provide either just the property name or type and property name (separated by a space). Types of the form string[] will result in a array typehint.
Phex supports multiple levels of configuration. Currently you can set the author, license and copyright information used by Phex in the PHPDoc when creating new classes and interfaces. You can set your default system settings by creating a file called phex.sublime-settings in Sublime's User/ directory.
For example, this file could look like:
{
"phex_default_author": "Florian Eckerstorfer <florian@eckerstorfer.co>",
"phex_default_license": "http://opensource.org/licenses/MIT The MIT License",
"phex_default_copyright": "(c) 2014 Florian Eckerstorfer"
}Additionally you can change these settings on a per-project basis. There exists a setting for the package PHPDoc tag. Your .sublime-project file could look like:
{
"folders": [
// ...
],
"settings": {
"package": "florianeckerstorfer/phex-test",
"author": "Florian Eckerstorfer",
"copyright": "2014 Florian Eckerstorfer",
"license": "http://opensource.org/licenses/MIT The MIT License"
}
}Note: You need to open the project in order to allow Phex to access these settings. If you open the directory (for example, by using the command line helper subl dir_name) Phex cannot access the settings and will fall back to the global settings.
PHP Extended contains all snippets from the default PHP package from Sublime Text 3 (some slightly modified to match the Symfony 2 coding standard) and adds new snippets.
The snippets are designed to be as short as possible and still intuitive.
In this documentation the snippets are organized by area of usage: methods, properties, variables and PHPDoc.
Snippets to create methods
| Tab trigger | Content |
|---|---|
pufun |
public function A(B) { … } |
pofun |
protected function A(B) { … } |
pifun |
private function A(B) { … } |
pusfun |
public static function A(B) { … } |
posfun |
protected static function A(B) { … } |
pisfun |
private static function A(B) { … } |
Snippets to create properties.
| Tab trigger | Content |
|---|---|
set |
public function setA($A) { $this->A = $A; return $this; } |
get |
public function getA() { return $this->A; } |
setget |
public function setA($A) { $this->A = $A; return $this; }
public function getA() { return $this->A; }
|
puv |
public $var; |
pov |
protected $var; |
piv |
private $var; |
pusv |
public static $var; |
posv |
protected static $var; |
pisv |
private static $var; |
Snippets to create and access variables.
| Tab trigger | Content |
|---|---|
rth |
return $this; |
-> |
$this->var = $var; |
ptr |
print_r($var); |
preptr |
echo '<pre>'.print_r($var, true).'</pre>'; |
vd |
var_dump($var); |
prevd |
echo '<pre>'; var_dump($var); echo '</pre>'; |
Snippets for PHPDoc.
| Tab trigger | Content |
|---|---|
indoc |
/** {@inheritDoc} */ |
Currently Phex extends the syntax highlighting provided by the default PHP package. I hope to extend this in the future.
The default PHP.tmlanguage only has support for PHPDoc annotations. Phex adds support for popular libraries
and their annotations.
Phex has syntax highlighting for annotations provided by Doctrine MongoDB ODM.
MongoDB\AlsoLoadMongoDB\BinMongoDB\BinCustomMongoDB\BinFuncMongoDB\BinMD5MongoDB\BinUUIDMongoDB\BooleanMongoDB\CollectionMongoDB\DateMongoDB\DiscriminatorFieldMongoDB\DiscriminatorMapMongoDB\DistanceMongoDB\Document)MongoDB\EmbedManyMongoDB\EmbedOneMongoDB\EmbeddedDocumentMongoDB\FieldMongoDB\FileMongoDB\FloatMongoDB\HashMongoDB\IdMongoDB\IncrementMongoDB\IndexMongoDB\IntMongoDB\InheritanceTypeMongoDB\KeyMongoDB\MappedSuperclassMongoDB\NotSavedMongoDB\PostLoadMongoDB\PostPersistMongoDB\PostRemoveMongoDB\PostUpdateMongoDB\PreLoadMongoDB\PrePersistMongoDB\PreRemoveMongoDB\PreUpdateMongoDB\ReferenceManyMongoDB\ReferenceOneMongoDB\StringMongoDB\TimestampMongoDB\UniqueIndex
Phex has syntax highlighting for annotations provided by Doctrine ORM.
ORM\ColumnORM\ChangeTrackingPolicyORM\|DiscriminatorColumnORM\|DiscriminatorMapORM\EntityORM\GeneratedValueORM\HasLifecycleCallbacksORM\IdORM\IndexORM\InheritanceTypeORM\JoinColumnORM\JoinColumnsORM\JoinTableORM\ManyToOneORM\ManyToManyORM\MappedSuperclassORM\OneToOneORM\OneToManyORM\OrderByORM\PostLoadORM\PostPersistORM\PostRemoveORM\PostUpdateORM\PrePersistORM\PreRemoveORM\PreUpdateORM\SequenceGeneratorORM\TableORM\UniqueConstraintORM\Version
Phex has syntax highlighting for annotations provided by Symfony2 Validation.
Assert\AllAssert\BlankAssert\CallbackAssert\ChoiceAssert\CollectionAssert\CountryAssert\DateAssert\DateTimeAssert\EmailAssert\FalseAssert\FileAssert\ImageAssert\IpAssert\LanguageAssert\LengthAssert\LocaleAssert\MinAssert\MinLengthAssert\MaxAssert\MaxLengthAssert\NotBlankAssert\NotNullAssert\NullAssert\RegexAssert\TimeAssert\TrueAssert\TypeAssert\UrlAssert\ValidUniqueEntity
Phex has syntax highlighting for annotations provided by PHPUnit.
assertbackupGlobalsbackupStaticAttributescodeCoverageIgnorecodeCoverageIgnoreStartcodeCoverageIgnoreEndcoversdataProviderdependsexpectedExceptionexpectedExceptionCodeexpectedExceptionMessagegroupoutputBufferingrunTestsInSeparateProcessesrunInSeparateProcesstesttestdoxticket
Phex has syntax highlighting for annotations provided by Gedmo Doctrine Extensions.
Gedmo\SlugGedmo\SoftDeleteableGedmo\TimestampableGedmo\Translatable
Phex has syntax highlighting for annotations provided by Braincrafted Validation.
BraincraftedAssert\Enum
- Added
Create Propertycommand Insert Class Namecommand now replaces the current selection with the class nameInsert Class Namenow shows the name of the class (instead of the filename) in the menu
- Initial release
- Included commands:
- Create class
- Create interface
- Insert namespace
- Insert class name
- Syntax highlighting for annotations
- Doctrine MongoDB ODM
- Doctrine ORM
- Symfony2 Validation
- PHPUnit
- Gedmo Doctrine Extensions
- Braincrafted Validation
- Snippets





