Include Library

Hi,

I am currently a Zend Studio user, I am mostly working with Zend Framework. I've been trying to switch (perhaps right term is -upgrade-) to PhpStorm. This is the first time I installed trial and experiencing the software. So far - I love it! The reason I've been using ZS like Notepad is the complexity of almost everything in the application. Anyway, I am not here to compare ZS with PhpStorm, but I have a question that will likely accelerate my switch decision if I can find a quick answer.

I do understand including libraries. Have a vendor folder in my local computer that I update when necessary and it includes all common libraries I need in my projects - ZF3, Doctrine etc.. I use this library in many projects so I don't want to download vendor folder from the remote development server for every single project into my local.

I included this folder as "Include Path"  in Languages & Frameworks -> PHP and it works ok. However, there are 2 things make me think:

1- Every single tutorial - video I had chance to read / watch show that entire vendor folder is always included in the downloaded files in the project.

2- When I debug the application, and try to step into the library script or click any of the processed scripts in Debug window, I get the following:

"Cannot find a local copy of the file in server ..."

I get it, so I have to make a path mapping but am I supposed to create mapping for every single project? Also, it will be always file by file mapping??? 

Can you please show me a source / tutorial / help topic to find out how to work with the libraries that I'll be using as shared?

Thank you very much.

 

0
4 comments

Hi there,

>1- Every single tutorial - video I had chance to read / watch show that entire vendor folder is always included in the downloaded files in the project.

That is correct -- if you include some folder as External Library (via "Include Path" functionality) then all files will be included. If you need to include only certain subfolders -- add them individually (e.g. "vendor/lib1", "vendor/lib3" etc)

>I get it, so I have to make a path mapping but am I supposed to create mapping for every single project?

Yes.

>Also, it will be always file by file mapping???

It's per folder actually -- all sub items (sub folders and files) will inherit mapping from the closest parent. But yes -- you can set any mappings for sub-folder/individual files.

>Can you please show me a source / tutorial / help topic to find out how to work with the libraries that I'll be using as shared?

I may only suggest to look here: https://confluence.jetbrains.com/display/PhpStorm/Tutorials -- I guess "Debugging with PhpStorm" would be the most correct section for this. But in general -- there is no much to talk about -- at very least that's how I see it. If you have specific questions -- feel free to ask.

-----

On a side note:

>I do understand including libraries. Have a vendor folder in my local computer that I update when necessary and it includes all common libraries I need in my projects - ZF3, Doctrine etc.. I use this library in many projects so I don't want to download vendor folder from the remote development server for every single project into my local.

Well .. the modern and recommended approach for the last couple of years is to use Composer (which by default will store all managed packages in "vendor" subfolder). If you do not use it yet -- you should start.

It sounds nice on paper to have one common "shared libraries" folder that is always has latest version etc..  but in reality (especially if you need to work with "fresh" projects and few projects that are not so "fresh") having separate local "vendor" (unique for each project) is much better (one library used in project #1 may not be compatible with library #2 used in another project etc).

Installing new/updating existing packages is easy -- "composer install" or "composer update" .. and it does the rest (so you do not even have to choose what to download from remote server). Plus, it manages dependencies for those libraries as well. Plus, it can manage autoloading with single require etc.

If you use Composer -- PhpStorm will do few things automatically for you (e.g. "vendor" is a local folder .. so files there should be treated as part of the project (which means -- you will see theirs todos, can edit those files etc) -- IDE will automatically exclude these packages and will add them back as Libraries so no such extra stuff in your actual project code).

Obviously, this all can be applied for new projects.. or if you can introduce composer in existing project. If it's some code that you do not have much control over (e.g. some project that you do small maintenance only .. or can do some bigger changes but you cannot introduce composer yourself) then you may just better stick to you current workflow.

0

Thank you, Andriy

I probably explained myself wrong. I am actually using composer - naturally. Every application already has different dependencies and packages.  There is nothing wrong at the server side.

It's all about setting up my local computer that PhpStorm is installed.

My local computer is different than the development server, so when I create the project in my local computer in PhpStorm, I select "New Project with Existing Files" and then "Web Server is on remote host, files are accessible via SFTP". 

I can simply download everything from the project root - that's fine but then I will have all shared libraries many times downloaded to my local computer. My approach in Zend Studio, creating an ALL-IN-ONE library so IDE can find whatever it needs without downloading vendor folder for every project. One project might not need zend-mail but other might need. Keeping ALL-IN-ONE library ready makes sure that zend-mail is ready for the IDE usage.

I think I am more related with this comment of yours:

PhpStorm will do few things automatically for you (e.g. "vendor" is a local folder .. so files there should be treated as part of the project (which means -- you will see theirs todos, can edit those files etc) -- IDE will automatically exclude these packages and will add them back as Libraries so no such extra stuff in your actual project code).

I think it is hard to explain since I am coming from ZS and both IDE has different structures about included libraries. I know it is the one right way reading everything to learn a new IDE properly :). I'll eventually figure it out, just wanted to make it faster to speed up the IDE switch I intend. 

Again, thanks for the reply.

 

0
Avatar
Permanently deleted user

> that's fine but then I will have all shared libraries many times downloaded to my local computer

You can add the path you don't want to upload/download to Preferences\Settings | Build, Execution, Deployment | Deployment > Excluded Paths.

0

Vladimir, thanks for your reply!

In fact, setting the Deployment Options when I first create the project in Phpstorm kind of the answer to my question. all folders under vendor folder has been magically added into the Include Path! I really have no idea how it happened but it did. 

Oh, there is so much to learn with the IDE! 

Thank you!

0

Please sign in to leave a comment.