Global and local include paths on per project basis

Hi all,

I just ran out of the 30 day trial and one thing that's keeping me from fully switching over to phpstorm is that I couldn't figure out is how to set up include paths on a per project basis.

I work on a remote webserver.

The folder structure looks as follows:
root/
├── _include/
├── Project 1/
│   ├── include/
│   ├── javascript/
│   ├── css/
│   └── index.php
├── Project 2/
│   ├── include/
│   ├── javascript/
│   ├── css/
│   └── index.php
└── Project 3/
    ├── Client 1/
    │   ├── include/
    │   ├── javascript/
    │   ├── css/
    │   └── index.php
    └── Client 2/
        ├── include/
        ├── javascript/
        ├── css/
        └── index.php

The Project and Client folders can access the global _include/ files.

Project 1 and Project 2 have their own include folders but you cannot include Project 1 files into Project 2 and vice versa.
Then there is also Project 3 which have multiple clients each with their own include path

We distinguish global includes and project/client includes in PHP by using 'require_once' for global includes and 'require' for project/client includes.

Currently I've setup _include/ as a global include in phpstorm and that works, but files that are included from the project or client specific include folders shouldn't be globally available, only for that specific project/client.

I've setup a content root for each Project and Client, from my understanding this is how it's supposed to be instead of having root/ as a content root.

For example the include path (php get_include_path()) of one of my projects is as follows:
"/var/working-www/griggigolik/_include:/var/working-www/griggigolik/Project 3/Client 1/include"

I hope all this is achievable or if there is some other way I should set up everything.

Thanks in advance!

0
6 comments

Do I get that right that in fact all projects and clients are opened as the same PhpStorm project, just different content roots?
If so, there's no way to separate them one from another. They all share the same settings and, consequently, the same include paths.
The only way is to keep each project and client as a separate PhpStorm project, with separate .idea directories.

0

Yeah, I only went through the File -> New Project from Existing Files once, then I set the content roots for the projects and clients. That way there is like you said only one .idea folder.

I tried what you proposed, I created a new project from existing files where the root isn't 'root/' but 'root/Project 3/Client 1/', then I created another project from existing files and I set that as 'root/Project 3/Client 2/' and attached it to the current window.

Now it neither finds the global 'root/_include/' files nor the local project include files (root/Project 3/Client 1/include). I can fix the global include by adding it in PHP -> Include Path, that still leaves me with the local include problem, adding that to the PHP -> Include Path isn't correct, cause if I do that, the local include files from Client 1 will resolve to Client 2 also.

I'm not sure where to go from there.

EDIT: So I tried this process again except this time is didn't attach the second project to the current window but instead I chose New Window. Setting the PHP -> Include Path to 'root/_include' and 'root/Project 3/Client 1' is what I had to do to fix the resolving issue.

One thing about this method is that it'll leave me open with a lot of windows over time, which I don't prefer.

0

That's unfortunate, if I wanted to continue using it with seperate windows for each project, how would I solve including the _include/ folder?

When setting up a window/project for Client 1 that only gives me access to those files and subfolders.
One thing I tried is creating a new project from existing files and selecting _include/ as a project then go to the Client 1 project settings and setting its PHP -> Include Path to the _include/ project.

This last option feels weird, how can I be sure that the files in the _include/ project are kept up to date if I only work in the Client 1 project?
And if I edit the _include/ project files from Client 1, would they be automatically rsync'd to the remote server?

All of that just feels wrong and inconsistent.

0

This last option feels weird, how can I be sure that the files in the _include/ project are kept up to date if I only work in the Client 1 project?
And if I edit the _include/ project files from Client 1, would they be automatically rsync'd to the remote server?

By default, no, but you can add extra mappings for the external folder to your deployment configuration to make sure they are.
PhpStorm will complain about the folder being outside the project, but deployment will work nevertheless.

0

Thank you for your support Eugene, for now I will hold off from using PHPStorm, I've got multiple devices that I would need to configure in the exact same way and that is just too much effort right now even with the synchronization setting enabled.

0

Please sign in to leave a comment.