php - Map one directory path to another in PHPStorm -
i'm using jetbrains phpstorm vagrant. host os (where phpstorm runs) windows, while guest os vagrant sets ubuntu linux. app resides @ /var/www/ in vm, on host code @ c:\code\.
therefore, in phpstorm, warnings unresolved directories, when in fact, path correct, , can mapped directly c:\code.

how can tell phpstorm paths in code start /var/www/ in project map c:\code\? i'd path inspections work again.
i never found solution this, thought post answer, i've since decided isn't great way build include paths in first place.
i came across better approach when reading through symfony framework (and composer's generated autoloader):
<?php // autoload.php @generated composer require_once __dir__ . '/composer' . '/autoload_real.php'; return composerautoloaderinitd1d12712f9bc55fdf8d19536f1f9dd88::getloader(); here, php magic constant __dir__ used starting point path. magic constant manual page:
__dir__directory of file. if used inside include, directory of included file returned. equivalentdirname(__file__). directory name not have trailing slash unless root directory.
there number of benefits approach:
- it's portable - work on operating system php run on
- it's flexible/dynamic - can move files around ,
__dir__constant reflect new path without code changes. - it's familiar - other developers more recognise approach, uses native language feature, , have come across before.
Comments
Post a Comment