PHP code example of nazonohito51 / require-path-fixer

1. Go to this page and download the library: Download nazonohito51/require-path-fixer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nazonohito51 / require-path-fixer example snippets


// before
nce __DIR__ . '/path/to/file.php';
;
        'file.php'     );
e UNKNOWN_CONSTANT . 'path/to/file.php';

// after
/file.php';
ce UNKNOWN_CONSTANT . 'path/to/file.php';


$fixer = new \RequirePathFixer\Fixer($inspectDirPath);   // It is strongly recommended that $inspectDirPath be a repository root.

$fixer->report($inspectDirPath, "APP_ROOT");    // Only reporting.
$fixer->fix($inspectDirPath, "APP_ROOT");       // Fix all files.
// The first argument of these methods is the base path of the modified statement.
// The second argument is a constant or method representing the base path.
// ex: "APP_ROOT", "Config::get('app.root')"

$fixer->addConstant('COMMON_DIR', '/path/to/common/dir/');   // COMMON_DIR will be replaced to '/path/to/common/dir/'
$fixer->addVariable('$smartyDir', '/path/to/smarty/dir/');   // $smartyDir will be replaced to '/path/to/smarty/dir/'

$fixer->addBlackList($inspectDirPath . '/vendor');
$fixer->addBlackList($inspectDirPath . '/tests');

$fixer->addWhiteList($inspectDirPath . '/app');

$fixer->setWorkingDir($inspectDirPath . '/public');

$fixer->setIncludePath(".:{$inspectDirPath}/app");

// before
nce (dirname(__FILE__).'/../app_root/' .'path/to/file.php');

// after

// before
nce $unknownVariable . 'path/to/file.php';

// after
nce $unknownVariable . 'path/to/file.php';

// before
nce './path/to/file.php';
/file.php';   // COMMON_DIR is './app_root/common'

// after
nce './path/to/file.php';
/file.php';

// before
nce './hoge/fuga.php';    // There is only one file that matches '/hoge\/fuga\.php$/'.
ga.php';

$fixer->setWorkingDir($inspectDirPath . '/public');

// before
h/to/file.php';   // COMMON_DIR is './app_root/common'

// after

$fixer->setIncludePath('.:' . $inspectDirPath . '/common');   // '.' will be replace current directory, but if it is not defined, '.' will be ignored

// before