Library in a different project

Answered

I have several projects which use my own library, which is in its own project.

My projects usually do have a lib directory where all libs (including the files from my lib project) go into on the server side.

So in my source code, the lib is missing but everything works fine when its on the server.

How would I add this lib project correctly into the PHP Library section?

 

6 comments
Comment actions Permalink

Correction: I was wrong, file paths are not being resolved relatively to the project root, only to the current file and PHP Includes.

I do have a lib directory in my projects and load these libs via required_once('lib/lib1.php') or required_once('../lib/lib1.php')

Let's take some certain project as an example, let's assume it's ~/PhpstormProjects/project1.

In this project, you have the lib directory.

When you require a file from the lib directory, statements like require 'lib/file1.php'; should work just fine after you add the project root as PHP Include.

Please confirm that it works this way.

http://prntscr.com/mljamq

1
Comment actions Permalink

I was wondering if you are already familiar with Include Paths option (check all the section):

https://www.jetbrains.com/help/phpstorm/configuring-include-paths.html

0
Comment actions Permalink

I tried to add an include path but I could not get it to work. It still says "file not found" for these libraries.

 

0
Comment actions Permalink

Do I get right that the issue is that require/include statements report the files missing?

If so, here's how PhpStorm resolves file paths:

1. Relatively to the current file location
2. Relatively to the project root
3. Relatively to PHP Include paths
3. Optionally, you can use $_SERVER['DOCUMENT_ROOT'] and set its location at Languages & Frameworks | PHP | Analysis

Unfortunately, since we don't know where exactly your files are located, and what are the require/include paths, we won't be able to provide you with precise instructions.

Maybe you can create a project sample so we could take a look at it?

0
Comment actions Permalink

@Eugene Morozov exactly.

My setup looks like that:

1. I do have a lib directory in my projects and load these libs via required_once('lib/lib1.php') or required_once('../lib/lib1.php')

2. I have my general library project, which contains only the lib directory and severa libraries I want to share between projects.

I tried to add the library projects root directory and also the lib directory in that project but PS was not able to locate the files.

 

0
Comment actions Permalink

You are right, this way it works!

I just have to add the include path to my server environment so ´lib/file.php´ works from everywhere. Thats where I struggled because I used relative paths like ´../lib/file.php´.

Thanks for your help!

0

Please sign in to leave a comment.