Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fukuoka Tech MTG vol.001

Fukuoka Tech MTG vol.001

Genki Uchimura

December 15, 2016
Tweet

More Decks by Genki Uchimura

Other Decks in Technology

Transcript

  1. 大量のrequire系ステートメントの存在 <?php require_once ROOT_DIR . ‘/foo/Foo.php; require_once ROOT_DIR . ‘/foo/Bar.php;

    require_once ROOT_DIR . ‘/lib/Baz.php; require_once ‘../../where/am/I.php; require_once APP . ‘/models/A.php; require_once APP . ‘/models/B.php; require_once APP . ‘/models/C.php; require_once APP . ‘/models/D.php; require_once APP . ‘/models/E.php;
  2. 1. 削除したrequire系ステートメントとそれが書かれていたファイルのパスを 収集 /** * getChangedFiles * * @param Gitonomy\Git\Repository

    $repo * @param string $revFrom * @param string $revTo * @return array */ public static function getChangedFiles(Repository $repo, $revFrom, $revTo) { return $repo->getDiff("{$revFrom}..{$revTo}")->getFiles(); }
  3. 2. requireに渡されているパス文字列(定数等含む)を取得 const INCLUDE_STMT_PATTERN = '/^(*)(include_once|include|require_once|require)(\((?P<required_file_1>.*)\)|+(?P<required_file _2>.*));( *)$/'; $isMatch =

    preg_match(Turpan::INCLUDE_STMT_PATTERN, $line, $matches); if (!$isMatch) { continue; } $tmp['file'] = realpath($file->getOldName()); $tmp['required_file'] = (!empty($matches['required_file_1'])) ? $matches['required_file_1'] : $matches['required_file_2']; $tmp['required_file'] = str_replace('__FILE__', "'{$tmp['file']}'", $tmp['required_file']);
  4. 使い方 Create example.php for example. <?php error_reporting(E_ALL && ~E_NOTICE); require_once

    dirname(__DIR__) . '/vendor/autoload.php'; use Turpan\Turpan; Turpan::run( dirname(__DIR__), //git repository path '1378949ebd23108b12bb0491f8e17684d142a285', //commit from '1826b68b66782d4920e0bfdeefd54a84aa0eb5e0' //commit to ); Then execute it. $ php example.php