Sei sulla pagina 1di 19

www.devsense.

com/products/php-tools

PHP Tools for Visual Studio


Introduction................................................................................................................................................... 3 About ......................................................................................................................................................... 3 Requirements ............................................................................................................................................ 3 Installation ..................................................................................................................................................... 3 Updating .................................................................................................................................................... 5 Automatic update notification .............................................................................................................. 5 Activating Trial license ............................................................................................................................... 6 Purchasing Professional features .............................................................................................................. 7 Commercial license for more users ........................................................................................................... 7 Working with projects ................................................................................................................................... 8 Opening an existing PHP web site ............................................................................................................. 8 PHP Editor...................................................................................................................................................... 9 Syntax highlighting .................................................................................................................................. 10 Custom colorization................................................................................................................................. 10 Smart Indentation ................................................................................................................................... 11 Automatic Formatting ............................................................................................................................. 11 Navigation bar ......................................................................................................................................... 12 Code collapsing & Outlining .................................................................................................................... 12 Code Snippets .......................................................................................................................................... 12 Insert Snippet ...................................................................................................................................... 13 Surround with ...................................................................................................................................... 13 Integrated documentation ...................................................................................................................... 13 Go To Definition (F12) ......................................................................................................................... 14 F1Help (F1) .......................................................................................................................................... 14 Code completion ..................................................................................................................................... 14 Go To Definition (F12) ............................................................................................................................. 15 Function assistance ................................................................................................................................. 15 Custom file extensions ............................................................................................................................ 16

- 1-

www.devsense.com/products/php-tools PHP Editor Options ...................................................................................................................................... 17 Debugging PHP code ................................................................................................................................... 17 Troubleshooting .......................................................................................................................................... 17 All the PHP code is gray ........................................................................................................................... 17 Unable to change some colors in VS11/Visual Studio 2012 RC .............................................................. 18 Cannot obtain a trial license .................................................................................................................... 18 Cannot activate professional features after the purchase...................................................................... 18 Slow or unstable PHP Editor .................................................................................................................... 18 Some of functions within my project are not included in IntelliSense lists ............................................ 19 Contact ........................................................................................................................................................ 19

- 2-

www.devsense.com/products/php-tools

Introduction
PHP Tools is lightweight PHP integration for Visual Studio focused on developer productivity. The integration understands your code, provides smart code completion, quick navigation, syntax error checking, integrated PHP documentation and more.

About
PHP Tools for Visual Studio is Visual Studio extension which adds PHP files code editor and project and item templates. The extension is based on .NET platform, focused on performance and stability. Support for integrated debugger is in-progress.

Requirements
Microsoft Visual Studio 2010, 2011 o Ultimate o Premium o Professional o (free) Integrated Shell 2GB RAM 1.4GHz dual-core processor Internet connection for additional features activation

Installation
The tool is distributed in a form of VSIX installation package. VSIX package is natural way of extending Visual Studio with additional features, can be easily installed and uninstalled without footprint on the target system. There are two ways of obtaining and installing PHP Tools integration: Extension can be installed from within Visual Studio (recommended). Open your Visual Studio, navigate to Tools -> Extension Manager -> Online Gallery and search for PHP Tools (see Figure 1 Installing PHP Tools from Extension Manager.). Visual Studio will offer you available products, you can continue to download and installation within one click. Note youll have to restart Visual Studio to finish the installation.

- 3-

www.devsense.com/products/php-tools

Figure 1 Installing PHP Tools from Extension Manager.

The package can be downloaded from Visual studio Gallery web and installed manually. Download package from http://visualstudiogallery.msdn.microsoft.com/6eb51f05-ef01-4513ac83-4c5f50c95fb5, run the downloaded file and follow on-screen instructions (see Figure 2 Installing PHP Tools using downloaded VSIX package.). Note it is recommended to close Visual Studio before installing. VSIX installer will show you whether there are Visual Studio products available for the package and whether there arent newer versions of the package already installed.

- 4-

www.devsense.com/products/php-tools

Figure 2 Installing PHP Tools using downloaded VSIX package.

Updating
To update the extension, you can either re-download VSIX package (see Installation) and run the installation manually, or take advantage of Visual Studio Extension Manager and its Updates tab (in Visual Studio, navigate to Tools -> Extension Manager -> Updates). Automatic update notification To be automatically notified about available updates, enable Automatically check for updates to installed extensions option (see Figure 3 Enabling automatic updates). This can be found in Options dialog in Visual Studio (navigate to Tools -> Options).

- 5-

www.devsense.com/products/php-tools

Figure 3 Enabling automatic updates

Activating Trial license


PHP Tools extension comes as freeware software with an option to activate professional features. After the startup of Visual Studio, youll see Licensing dialog with current state of licenses and enabled features. (As depicted on Figure 4 Preview of licensing window.). You can disable displaying of this dialog (by ticking the checkbox on lower left corner of the dialog), simply close it, activate Trial license or purchase Professional features with a year of updates. The dialog is displayed any time you use features that are not available with your current license (e.g. when you press F12 (Go To Definition) inside PHP code) or by navigating to Help -> PHP Tools for Visual Studio. Trial license is immediately activated by clicking on Begin Trial button. This allows you to evaluate full-featured PHP Tools unlimitedly for 21 days. The activation process requires working Internet connection to be able to obtain a license from our online storage. After the trial license activation, you can check remaining days in the licensing dialog each time your Visual Studio starts. When your license expires, youll be notified automatically with the same dialog; this allows you to disable displaying of the dialog or purchase Professional features.

- 6-

www.devsense.com/products/php-tools

Figure 4 Preview of licensing window.

Purchasing Professional features


Within the licensing dialog (see Activating Trial license), you can purchase Professional features with a year of updates and technical support. Click Buy Now button to be automatically navigated to a web site with license selection and direct payment button. Note, to activate your purchased license, you need an Internet connection. After the purchase is made, click Activate product to enter license key and activate online. In case of failed activation, please contact us at info@devsense.com.

Commercial license for more users


When purchasing commercial license (within Purchasing Professional features), you can specify you would like to buy more than one license. In such case, youll get one license key that can be used for up to specified amount of developers. This allows your company or an organization to purchase PHP Tools for more than one developer within single invoice and license key. License keys are managed on our online storage, and any license upgrades can be made without a developer interaction. After the purchase, enter your license key within licensing dialog (see Figure 4 Preview of licensing window.) using Activate product link. This activates your license key on current computer online. Note you need an Internet connection of course. The license key can be found on your invoice.

- 7-

www.devsense.com/products/php-tools

Working with projects


Code sense features work only within a project opened in Solution Explorer. If you open a code file that is not a part of any opened project, you wont see functions, variables, classes, namespaces () from other (even included) files. Opened PHP project is depicted on Figure 5 Preview of Solution Explorer with an opened Web Site.

Figure 5 Preview of Solution Explorer with an opened Web Site.

Opening an existing PHP web site


You can simply open an existing PHP project using Visual Studio. Within Visual Studio, navigate to File -> Open -> Web Site to open a dialog that guides you thru the process of opening a web site. You can open a PHP project or create new one from: An existing IIS virtual directory. Simply open a web site that is already configured on your local IIS. Source Control; which depends on your source control providers currently installed. Remote Site. FTP site. File system. This allows you to open any folder you have locally and to work with it as with a PHP project.

The process is depicted on Figure 6 Preview of Web Site open dialog.

- 8-

www.devsense.com/products/php-tools

Figure 6 Preview of Web Site open dialog.

You can open several projects within one solution. This allows you to manage more projects within one Visual Studio instance and to work between more PHP web sites.

PHP Editor
PHP Editor integration adds support for .php files into Visual Studio, and an option to specify additional file extensions (see Custom file extensions). This support makes PHP code highlighted, with additional features listed in this section. As of May 2012, PHP 5.3 compatible constructs are supported.

- 9-

www.devsense.com/products/php-tools

Syntax highlighting

Figure 7 PHP code syntax highlighting preview.

Syntax highlighting feature makes PHP code more readable as any other language file integrated in Visual Studio. Script code blocks, variables, keywords, strings, script tags and comments are distinguished to make programming easier. When PHP Editor finds a syntax error or a logical error, corresponding expression is underlined with red wave and the error detail is listed in Visual Studios Error List tool window.

Custom colorization
PHP Tools editor respects your custom color settings from Visual Studio. These settings can be configured in Tools -> Options -> Environment -> Fonts and Colors (see Figure 8).

Figure 8 Custom color settings dialog.

- 10-

www.devsense.com/products/php-tools The editor uses all built-in settings. This lets you to use PHP Editor with your existing custom settings easily. Following Display items affects PHP Tools Editor
Keyword Affects PHP keywords, such as for, while, if, function. Comment Color of inline comments and content of PHPDoc. Identifier Any identifier, such as a function name or a class name. String Color of string literals, enclosed in or quotes. Number Numeric literal. Text Other simple symbols, including commas and operators. HTML Server-Side Script PHP starting and ending scripting tags (<?php ?>) HTML Attribute Name Color of HTML attribute name. HTML Attribute Value Color of HTML attribute value. PHP - Encapsulated Variable Color of a variable name within a string literal. PHP - Variable Color of variable name. That is typically a symbol starting with $ character. PHP PHPDoc Keyword Color of special keywords and comment tokens within PHPDoc.

Smart Indentation
PHP editor supports smart indentation feature. It should be enabled by default, otherwise go to Tools -> Options -> Text Editor -> PHP -> Tabs, and select Smart in the Indenting options group. Smart Indenting automatically indents or outdents new lines. It recognizes what you are actually typing: <enter> key will place your caret to the best position for new statement or for continuing unfinished statement. This also works within PHPDoc or multi-lined comments, by adding * at the line beginning. { character outdents current line to line up with code block start. } character outdents current line to match block start. If the code is syntactically valid, it also reformats code block (see Automatic Formatting). : after case or default makes indentation of the line the same as other cases within the switch.

Automatic Formatting
You can fix indentation and code formatting automatically by pressing Ctrl+K,D. This will reformat PHP code within the whole document, and adds additional new lines where they should be, to make your code more readable and to preserve formatting conventions across the whole project. PHP editor also supports reformatting of a text selection only. Select code fragment and press Ctrl+K,F to reformat only a piece of code. Formatting selection is called automatically on code blocks that you just closed with } character (you can always disable this feature in PHP Editor Options). Automatic Formatting respects common programming conventions and Visual Studio conventions. It keeps your new line breaks, keeps single-lined <?php ?> blocks and your custom indentation settings.

- 11-

www.devsense.com/products/php-tools

Navigation bar

Figure 9 Navigation bar feature preview.

Every PHP file gets navigation bar at the top of editor. This bar shows two drop-down lists: Type list shows classes and interfaces within current file. You can quickly navigate to a class or interface definition by selecting it from the list. Member list shows either global functions (if no type is selected in the first list) or list of toplevel class members (if a type is selected in the first list). Every listed symbol is marked with an icon, name and occasionally parameters in case of a function. In case of class member, only toplevel members are listed; members in parent classes are ignored.

Code collapsing & Outlining

Figure 10 Code collapsing feature preview.

PHP Editor allows you to collapse functions, classes, namespaces and PHPDoc to make better overview of your code. By default, Collapse to definition is associated with shortcut Ctrl+M,O, and disable outlining with Ctrl+M,P. If you have a cursor inside a collapsible block (which is represented by a thin line on the left side of editor) you can press Ctrl+M,M to toggle its state.

Code Snippets
PHP Editor supports snippets; small pieces of most used code fragments to be inserted within as little keyboard hits as possible to save time and avoid common typos. Most used code snippets are if, for or switch. By inserting these keywords as snippet, whole standard body of the statement is inserted instead.

- 12-

www.devsense.com/products/php-tools Insert Snippet

Snippets can be inserted in two ways: Snippets browser. Small tool window with list of available snippets can be opened anywhere in PHP code. By subsequent typing, selecting and pressing enter key, code snipped is inserted at the current caret position. By default, snippet browser is opened by pressing Ctrl+K,X or by mouse right click and choosing Insert Snippet command. Inserting snippets only works within PHP code block. Code completion drop down. Code snippets are included as a part of code completion list (see Code completion). Keywords supporting snippet insertion are marked with special icon. By pressing tab key the keyword is inserted as a snippet.

Surround with In addition to inserting clean snippets, you can surround an existing code with the snippet code. It is very useful feature allowing you to easily create e.g. function, a loop or try block around an existing code. To choose a snippet you would like to use, press Ctrl+K,S (default) or use right mouse click and select Surround with command. Snippet browser will pop up, and chosen snippet will surround selected text.

Integrated documentation
PHP editor contains database of built-in PHP functions, classes and constants, contained in every official PHP extension. Every symbol is annotated with detailed documentation. This means youll see description of anything you are selecting from IntelliSense lists or mouse hovering. When you are typing, PHP Editor shows a list of available symbols within your current code context. After highlighting a symbol in the list, tool tip bubble is displayed aside of the drop down list with complete symbol declaration and its description. This makes you easier to check anything you are about to use, without a need of navigating to documentation on web. - 13-

www.devsense.com/products/php-tools

Figure 11 Tool tip assistance with documentation from PHPDoc.

Mouse hovering over a word (functions, class name or a class) shows the same tool tip bubble, so you can ensure about functionality of code you are using instantly. Go To Definition (F12) PHP Editor also supports Go To Definition feature. Right click on a word or simply press F12 to navigate to a symbol definition. By navigating to a definition of built-in PHP declaration, PHP Editor will generate PHP code corresponding to its specification, including its documentation (as VisualStudio developers are used to). F1Help (F1) Built-in PHP functions, classes and class functions can navigate you to PHP manual page directly. Place a caret cursor onto the desired symbol and press F1. This will open your web browser at corresponding page so you can find more details, related declarations or users discussion.

Code completion

Figure 12 Code completion IntelliSense feature.

When typing a word, PHP Editor popups list of possible symbols that would autocomplete so-far typed word. The list also shows associated documentation obtained from built-in symbol database or related PHPDoc comments. Auto-completion takes into account current code context and the whole expression chain.

- 14-

www.devsense.com/products/php-tools Note: this feature works for global code, local code, namespaces, variables, constants, classes, functions, instance members and class static members. All listed symbols are estimated using code analysis; some symbols may be missing or there can be listed symbols that would not be present in run-time. To make code completion as precise as possible, write PHPDoc with @return type specified, @var type, use unique names of variables and in general; write code clean. Code completion after keywords such as new, global, extends or implements shows only symbols available in this context. Code completion can be always displayed at any location by pressing Ctrl+Space (by default). Code completion, tool tip assistance, function assistance and Go To Definition features need information about files in your PHP project. All the project files are processed every time you open PHP project and use one of the feature above for the first time. This may take some time, and you will be notified about the progress in Visual Studios status bar at bottom of window. During the processing some of symbols may not be displayed within IntelliSense lists or may not be available in for other code sense features.

Go To Definition (F12)
PHP Editor supports Go To Definition feature which navigates you to definition of symbol under the cursor. This feature recognizes following symbols: In case of variables, youll be navigated to all estimated variable initialization expressions. This represents common way of declaring variables in PHP. Indirect variable usages are ignored. Navigating over a function call offers definitions of all functions with the name under the cursor. All the Classes with the name specified under the cursor are offered. Constants within define() function call or const declaration statement are recognized. Class members of object instances and static members of types are supported. Note the type of class instance has to be estimated, and more or none results can be offered based on the estimation.

If there is just one possible result, youll be navigated instantly. In case of none or more than one result, Find Symbol Results window is opened so you can select one or cycle through all of them.

Function assistance

Figure 13 Method info bubble.

By typing ( or , characters, PHP Editor looks onto code and shows information about function before the cursor. In the showed bubble (see Figure 13 Method info bubble.) you can see all the possible function overloads in case there would be more possibilities in run time.

- 15-

www.devsense.com/products/php-tools The bubble contains function name, documentation if available, and parameters with estimated types and initial values for optional ones. Every parameter can also be tagged with documentation.

Custom file extensions


A lot of PHP projects (like Drupal) use various file extensions for their PHP scripts. With PHP Tools, you can assign additional file extensions to PHP Editor. This allows you to work with .inc, .php5, .module or any other file type, taking advantage of all the smart code completion features and highlighting.

Figure 14 Additional file extensions configuration.

The feature can be configured within Visual Studio, go to Tools -> Options -> Text Editor -> File Extensions. Enter your file extension in the text box, select PHP Editor from the list and click Add. The configuration dialog is depicted on Figure 14 Additional file extensions configuration. Note it is recommended to restart Visual Studio to be sure your changes are accepted by opened projects within your Solution Explorer.

- 16-

www.devsense.com/products/php-tools

PHP Editor Options

Figure 15 PHP Text Editor options.

PHP editor is configurable in Tools -> Options -> Text Editor -> PHP. See Figure 15 PHP Text Editor options. You can modify indentation behavior, whether <tab> key inserts tabulator character or spaces and other options.

Debugging PHP code


This feature is currently not available for public.

Troubleshooting
All the PHP code is gray
This issue is mostly caused in two cases. The PHP Tools extension is not installed or is disabled. Within Visual Studio, navigate to Tools -> Extension Manager, and check whether you have PHP Tools installed, whether there are no conflicts with other PHP extensions and whether the extension is not disabled. Note when enabling extension, other running instances of Visual Studio may cause disabling it again. Default editor for PHP files has been changed. Sometimes users without PHP integration configure their Visual Studio to open PHP files with HTML editor or XML editor instead. PHP Tools are not able then to control PHP files. To fix this, go to File -> Open -> File, navigate to any .php file on your system, and click Open With (small black arrow aside of Open button). - 17-

www.devsense.com/products/php-tools

In the opened dialog select Source Code (Text) Editor or PHP Editor and click Set as Default.

Unable to change some colors in VS11/Visual Studio 2012 RC


Currently there is misbehavior in VS11 and Visual Studio 2012 RC causing additional colorable items (PHP Encapsulated Variable and PHP PHPDoc Keyword) are not available within Fonts and Colors options dialog (see Custom colorization). To fix this follow the thread on our support forum at http://support.devsense.com/viewtopic.php?f=21&t=643&p=3059#p3059.

Cannot obtain a trial license


To enable professional features, by clicking on Try button within Welcome screen, you need an Internet connection. Check your Internet connection and try again. In case the process still fails, please contact us at info@devsense.com.

Cannot activate professional features after the purchase


To enable professional features you need an Internet connection. Check your Internet connection and try again. With working Internet connection, try to enter license key within licensing window, by clicking on Activate product button. In case the process still fails, please contact us at info@devsense.com.

Slow or unstable PHP Editor


The PHP Editor is fine-tuned to work fluently with vast array of existing PHP code. It is possible youve found a case causing internal code analysis working slower. You can report such issue to us at http://support.devsense.com/viewforum.php?f=21. Any feedback is appreciated. We will make our bests to improve the editor.

- 18-

www.devsense.com/products/php-tools

Some of functions within my project are not included in IntelliSense lists


Ensure you have opened a PHP project (see Opening an existing PHP web site) including files containing your functions first. If there are syntax errors, PHP Editor would not be sure about your function declarations and may exclude them from IntelliSense lists.

Contact
PHP Tools for Visual Studio is developed and supported by DEVSENSE. http://www.devsense.com/products/php-tools - product web site, features, pricing, demos. http://www.devsense.com/ - company web site. http://visualstudiogallery.msdn.microsoft.com/6eb51f05-ef01-4513-ac83-4c5f50c95fb5 - Visual Studio Gallery, rating, downloads, statistics, current version download.

- 19-

Potrebbero piacerti anche