This used to work, but it stopped working recently. I don't think anything changed in my settings, but I have poured over them for a couple hours now just to make sure. I have checked all over google and SO too. Please pay attention to the details before claiming "this was answered over here..." Thanks. :)
Assumptions and Requirements
Assume we have two files:
<project_root>/index.php
<project_root>/folder/file.php
Assume our project root is /home/me/project.
We want to include file.php from index.php. We expect PhpStorm to be able to resolve the file path and allow us to do nifty IDE things like "Go To Declaration."
What works
require 'folder/file.php';
require '/home/me/project/folder/file.php';
$root = '/home/me/project/';
require $root.'folder/file.php';
What No Longer Works
define('ROOT_DIR', "/home/me/project/");
require ROOT_DIR.'folder/file.php';
PhpStorm does recognize the value of ROOT_DIR when I mouseover, but it highlights home and says something like: Path '"/home/me...folder/file.php' not found
Why Use a Constant Anyway?
To keep this simple, I've left out details that are not necessary to illustrate the problem. The primary thing I'd like to address is why this used to work but no longer does, and/or how can I make it work again.
Sorry, can't help. What are you really trying to do?
Here are the details I left out. If we can't solve the primary issue, perhaps we can find a good work around.
I'm working with an existing codebase. Most files require a config.php file that defines root_dir() for getting the web/project root. PhpStorm wasn't resolving those paths (understandably so), so I created a constant to takes it's place. That makes more sense anyway.
In today's battle, I discovered that you can do this:
/** #define "root_dir()" "/home/me/project/" */
// or
/** #define "ROOT_DIR" "/home/me/project/" */
If you put that anywhere in the file then PhpStorm is able to resolve all the includes/requires in that file. BUT, it only works in that file, even if you try to include/require it in another file. You'd have to do this to EVERY file to get it working everywhere. Nope. Nuh-uh. No thank you. I need to reference the absolute path to the project/web root in a way that PhpStorm will recognize across the whole project.
#LazyOne answered this in the comments. This is a bug in the latest release, and it's being tracked here: https://youtrack.jetbrains.com/issue/WI-31754
Until this gets patched I've created this work around:
Using Keyboard Maestro, I created a hotkey that will paste the #define comment at the top of the file and return the cursor to its original position. Download the macro here. Import that and edit the text.
Edit: You may actually need to edit the file in a regular text editor. One of the file paths may need to be changed to work on your system.
Note: I'm using a modified version of the Mac Eclipse keyboard layout in PHPStorm. I'm not sure that will matter.
Also, be aware that many of your "changed files" will simply have this mapping at the top of the file, and this mapping may not be correct for you teammates. I'm simply excluding those changes from my commits.
Related
I've taken over a code base of a Symfony 4.4-project, with a couple of extra bundles installed (Sonata being the biggest one). When I write: php bin/console list, then it prints the source code for several of the classes in the src/Admin-directory. And I can't figure out why.
I've searched the code for print, var_dump and dump, but can't figure out where this is.
I'm not familiar enough with Symfony, to go through the code 'from the top', adding my own dump-statements, narrowing it down, where this code is coming from.
Had this been Laravel, then I would have started in the routes, then moved on to maybe the kernel or middleware, then to the controlles - and in the end the views.
Does anyone have a good suggestion on which files to add dump-statements to, to see where this code is coming from?
... Or if anyone else has a good idea on how to find this code, then I'm all ears.
Is it maybe an entire namespace that is printed? And can one even do that?! Hmm...
This is what it looks like:
You'll get this behavior if the code you've inherited uses short open tags <? but your personal dev environment's PHP installation has them disabled. Run php --ini to find where your ini file is and then edit that to change from this:
short_open_tag = Off
To this:
short_open_tag = On
Alternatively, you could edit all the source files and change the short open tags <? to long open tags <?php.
My vscode does not see the definition of functions in vendor library.
I don't know if it has anything to do with gitignore, where I have put vendor, but I would like to find a solution that lets me keep it in gitignore, but allows me to search through in the work environment.
Because it does not see the definition, it gets underlined as a problem and I can not take a peak into what I am working here with.
It does not affect the resulting outcome, it is problem while using the vscode.
Can you please help?
I tried creating config.json in the project root folder .vscode saying:
{
"search.useIgnoreFiles": false
}
It didn't do anything.
Thank you for looking into it.
Add the direcory path into intelephense configuration:
#ext:bmewburn.vscode-intelephense-client
Like here into include path list:
I have the following folder structure:
Previously, the classes were placed directly in /rest/ folder and they were referenced so in autoload.php:
After doing Refactor->Move for all classes in PhpStorm to /rest/class/ directory, PhpStorm does not refactor string file paths (seen on the above screenshot). Does someone know why is that? Standard filename refactor works fine. Is there better way to change folder structure for the project without the need to check all the references in other files?
This issue has been reported some time ago as https://youtrack.jetbrains.com/issue/WI-33398 but did not have much votes there. Would be great if you could vote for it with Thumb Up button and leave a comment to get a devs attention.
I have installed a security solution in my Joomla website,and it's suggest that to put the configuration.php file above the Public_html Folder,how could it be possible?
how to tell the CMS to recognize the new location?
is the solution would be valid in all versions of the Joomla CMS? ,if it's not,so please
write:
1st:Joomla 2.5 Solution.
2nd:Joomla 3 Solution.
you would need to modify the defines.php file located in the includes folder.
Specifically this line:
define('JPATH_CONFIGURATION', JPATH_ROOT);
And change JPATH_ROOT to the correct path.
But the problem with this is that you are modifying a core file so if an update changes the defines.php file it will overwrite your changes and will break your setup. You will need to reedit the file.
Also the JPATH_CONFIGURATION constant may be used for other things within the CMS that are not specifically trying to get the configuration.php file so make sure to check that it will not adversely affect other parts of the cms before doing this in production.
Alternatively you can change the frameworks.php file (also in the includes folder) directly to change from where the configuration is loaded from
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();
Just change the require_once line to the correct path.
Again since this is a core file it could be changed by an update. But this may also affect other parts if the config file is loaded manually in components or other parts of the cms.
Simply answer is don't do it. This would mean you would have to do what #Patrick has suggest which is correct and will work, however it means editing a core Joomla file. This is not a good idea as in your case, if you ever update Joomla, you will have to perform this change every time and it you forget (which is likely), your site will stop working completely.
I would strongly suggest you find a different "security solution" which does not involve having to modify any core Joomla files.
If you could define what you mean by "security solution", then maybe an alternative could be provided for you
I didn't dig for 'since when this has been implemented', But it can be done without changing the core.
Joomla looks for a defines.php in the root and if its present, imports it. And then if it finds a constant named _JDEFINES defined, it doesn't load the original file, effectively overriding it completely.
So, If you wish to override the defines its pretty easy and all you have to do is copy the contents of the defines.php file from under the webroot/includes/ path and paste it inside the one we created in the webroot. And you can change the following constant as per your taste.
define('JPATH_CONFIGURATION', JPATH_ROOT."/my/supersecret/directory");
Now there is one more thing left to be done and then we are good to go :)
You have to prepend the following lines to the top of our override file (the defines.php in the webroot).
define('JPATH_BASE', __DIR__);
define('_JDEFINES', 1);
This constant conveys to the framework that the defines have been overridden and to use the new file accordingly (Last time I checked, this flag/constant is checked at around 10 different places all over the framework eg. here, so its important)
Also I have seen this feature available with Joomla v2.5.0 and v3.8.8 as per your requirements in the question.
Edit: Remember you have to repeat the same procedure for administrator folder too if you want admin panel to work, and remember that administrator has its own /includes/defines.php
Hi this is my first post on here. I am trying to install the Gdata Zend Client library without much success.
I have used these resources + scoured Stack Overflow.
https://developers.google.com/gdata/articles/php_client_lib
http://jeromejaglale.com/doc/php/google_calendar_api
I want to be able to add,edit etc events on google calendar via PHP. My problem/question is i really dont understand what the include_path settings are all about and how to set them in order to make the class work. Of course i checked php manual regarding this but still draw a blank.
I have downloaded the relevant class and uploaded it to my web root. In the past i would just include a class by using php include at the top of the page and this would suffice.
I am of the understanding that i need to change the php.ini file to show php where my class is. Does this mean that i have to put my class somewhere else other than the web root.
I am terribly confused about this step and i know that if i can get it installed, actually using the class should be relatively easy.
Thanks for any help.
Welcome! Your Q is about include files rather than ZF elements.
Understanding where the include setting can be made (and subsequently overridden) is an absolute key bit of information.
You need to find out where it is on the server you are working on.
echo ini_get('include_path');
Then dash off and really, really read the corresponding manual page.
Try out including a very simple file with an echo statement, and you will regain your sanity and confidence.
http://www.php.net/manual/en/function.include.php
Get that working then have a play with this:
http://www.php.net/manual/en/function.ini-set.php
The experience how you can include a file from the same directory (not generally a good idea if that is a public webpage - inside your webroot)
Then if you want to really chase this thing down, look at where you can set this in Apache and per-directory in .htaccess files.
Finally, you can just include a file by telling include/require the exact path from the top of the tree;
include /var/www/includes/libraries/and/so/on.php;
There are SO many places you can set and override this that you are really best off finding out where the server thinks the include directory is and putting your compoenents in there:
Now, when that comes to ZF stuff, I (on Deb and Ubuntu anyhow) put the contents of
Zend Framworks version XYZ ZendFramework/lib/Zend <-that folder into:
/usr/share/php/Zend <-into this place
Then setup your autoloader and Robert is your mothers brother...
Zend/Gdata.php line 124 is like this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’)
Change that to this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’, $useObjectMapping = true)