-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Place } from './Place'; | ||
|
||
export class Config { | ||
static readonly patterns = [ | ||
/Config::[^'"]*(['"])([^'"]*)\1/, | ||
/config\([^'"]*(['"])([^'"]*)\1/g | ||
]; | ||
|
||
public getPlace(path: string, line: string, lines = ''): Place { | ||
const place = new Place({ path: '', paths: new Map, location: '', uris: [] }); | ||
|
||
for (const pattern of Config.patterns) { | ||
const match = pattern.exec(line) ?? pattern.exec(lines); | ||
if (!match) { | ||
continue; | ||
} | ||
|
||
const split = path.split('.'); | ||
place.path = 'config/' + split[0] + '.php'; | ||
if (2 <= split.length) { | ||
place.location = "(['\"]{1})" + split[1] + "\\1\\s*=>"; | ||
} | ||
return place; | ||
} | ||
|
||
return place; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as assert from 'assert'; | ||
import { Config } from '../../Config'; | ||
|
||
suite('Config Test Suite', () => { | ||
const config = new Config; | ||
|
||
test('facade config', () => { | ||
let place = config.getPlace('app.timezone', `Config::get('app.timezone');`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
|
||
place = config.getPlace('app.timezone', `Config::set( 'app.timezone', 'UTC');`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
}); | ||
|
||
test('config helper', () => { | ||
let place = config.getPlace('app', `config('app');`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
|
||
place = config.getPlace('app', `config('app.{$var}');`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
|
||
place = config.getPlace('app.timezone', `config('app.timezone');`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
assert.ok(place.location.includes('timezone')); | ||
|
||
place = config.getPlace('app.timezone', `config( ['app.timezone' => 'UTC']);`); | ||
assert.strictEqual(place.path, "config/app.php"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters