Share common files between projects

Using PhpStorm 8.0.2 build number PS-139.659

I would like to setup a structure to share common files between projects. I've tried to find something on this in the help and also in the discussion forum, but I must not be search using the correct terms.

Can someone point me in to the documentation that will allow me to setup a project and gain access to a common 'pool' of files (e.g. TinyMCE, utility PHP I've created, etc.)?

Regards,
Rich

7 comments
Comment actions Permalink

Hi there,

1) You can attach any content as additional content root: "Settings (Preferences on Mac) | Project | Directories --> Add Content Root"

2) You can reference folder via "Settings | Languages & Frameworks | PHP | Include paths" -- same idea as PHP's own include_path -- such folders will be listed under "External Libraries" branch in Project View.

3) JavaScript libraries -- the same: you can create global one (Settings | Languages & Frameworks | JavaScript | Libraries) that will be accessible to all projects and will be listed under "External Libraries" branch in Project View.

4) Using file system only --- symbolic links. Just a note: you will need to specify correct path mappings when debugging such PHP code (if everything is local, of course) as xdebug works with final/resolved paths only.

0
Comment actions Permalink

I'm missing something. I have a php file called rw.sysutils.php that is listed under 'external libraries'. I'm developing a class that calls a function in rw.sysutils.php, but when I run the class I'm developing, I'm getting the error PHP Fatal error:  Call to undefined function xxxxxxxx() in path and filename of class being tested.

I do not have an include or include_once in the class php file I'm developing.

Regards
Rich.

0
Comment actions Permalink
I do not have an include or include_once in the class php file I'm developing.

You should have it.

0
Comment actions Permalink

Okay, I added the include. Still no success.

The include is coded as:

  include "rw.sysutils.php";

Do I need the path? If so what path should be provided? I did do a copy reference and all that is pasted is the file name, e.g. rw.sysutils.php (no path).

Is there something I cold provide you that could help identify my problem?

I am using Windows 7 (64bit)

Rich

0
Comment actions Permalink

First of all you have understand that whatever files you reference via "Settings | PHP | Includes" or as "Additional Content Root" -- it's for IDE eyes only so it can index those files and resolve any references (class names/variables etc).

You have to treat your project as if it's done in basic notepad which has no clue at all about PHP / as if you use PhpStorm for coding only and execute the actual code elsewhere. This means: you have to build your include/require statements in such way that allow PHP to find those files.

Do I need the path?

Yes. It could be absolute path from the root .. or relative to current file (e.g. "../../myLib/myFile.php").

Alternatively add the path where that file is colated to your "include_path" PHP setting (can be done dynamically -- http://uk3.php.net/manual/en/function.set-include-path.php ) -- PHP will check all paths there when searching for files in include/require statements.

0
Comment actions Permalink

Andriy, thank you. You have provided a missing piece for the PHP.INI file, that is, the 'include_path' key. I've setup an include path on my IIS server that I will use when I deploy my system utilities. On my development system, I've update the PHP.INI to point to  my project lib folder so I can do development/testing of classes that will use the proper utilities.

Now, for my settings, under LANGUAGE & FRAMEWORKS for  PHP do I need to add an 'Include path' for my includes so I don't get syntax errors when including the system PHP files?

Rich

0
Comment actions Permalink
Now, for my settings, under LANGUAGE & FRAMEWORKS for  PHP do I need to add an 'Include path' for my includes so I don't get syntax errors when including the system PHP files?

Not 100% on what you mean here .. but in general: if you have files that are located outside of the project but used in your project .. then yes -- add path to such folder here so that IDE will scan those files for references (class names etc) as IDE will not check your php.ini's include_path automatically.

0

Please sign in to leave a comment.