Working with Refactoring
The purpose of this tutorial is to teach you how to refactor your code to easily rename and move files and elements without damaging your projects or severing the link between referenced items, as well as creating the necessary links between PHP elements in separate files.
Purpose and Usage
The Refactoring feature allows you to:
-
Rename and move files and elements within those files, while maintaining the links between the items. Once an element or file has been renamed or moved, all instances of that item within the project will be automatically updated to reflect its new name / location.
-
Organize Includes so that elements from one file can be referenced in another file.
Refactoring should be used when you are reorganizing your project and changing names and locations of files and elements.
Note:
Refactoring will only work from within PHP Explorer view and not from Navigator view.
Renaming / Moving Files
Renaming a file will result in the automatic renaming of all instances where that file is referenced within the project.
|
|
|
This procedure demonstrates how to Rename a file:
<?
<? require(RenFile1.php);$a = 8;? Note: Ensure you delete the PHP tags that are inserted by default when creating a new PHP file before pasting in the code.
|
The reference to RenFile1 in RenFile2 will have been updated to: require(RenFile3.php); in order to reflect the changes in the file name. |
Moving a file will result in the automatic updating of all instances where that file is referenced within the project to reflect its change of location.
|
|
|
This procedure demonstrates how to move a file:
The Preview windows will display the changes that the move will apply to your script. Note that RenFile1's new location will automatically be updated in the reference to it in RenFile2.
|
|
Renaming Elements within a File
All PHP Elements (e.g. classes, interfaces, functions, methods) can also be renamed and refactored from within the editor window.
|
|
|
This procedure demonstrates how to use the Rename Elements feature:
|
|
Organizing Includes - (Studio6)
Using the Organizing Includes feature will allow PHP objects created in one file to be called into other files within the project.
|
|
|
This procedure demonstrates using the Organizing Includes feature:
<?php class MyClass {} ?>
<?php function myFunction() { return 1; } ?>
<?php $z = new MyClass(); echo myFunction(); ?> Note that the code in OIFile3 attempts to call MyClass and myFunction created in OIFiles 1 and 2.
|
Note: If two elements of the same name are recognized, a window will display so that the relevant one can be selected. |
The Organize Includes feature can also:
-
Delete references and "include" calls to files if the relevant items have been deleted from the code.
-
Move "include" calls to the top of your script if they have been placed further down, in order for the elements to be referenced before the script is run.
|
|
|
Related Links: Organizing Includes |
|
|