Last active
March 21, 2016 14:22
-
-
Save zdenekdrahos/8999a11347cb0df2be5a to your computer and use it in GitHub Desktop.
Nette - bootstrap (https://quip.com/1DAjAVxx9gZ8)
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
<?php | |
// app/bootstrap.php | |
function getService($service, array $config = []) | |
{ | |
return initApplication($config)->getService($service); | |
} | |
function initApplication(array $config) | |
{ | |
static $container = null; | |
if ($container == null) { | |
$configurator = new Nette\Configurator; | |
if (in_array('enableProduction', $config)) { | |
$configurator->setDebugMode(Nette\Configurator::NONE); | |
} | |
if (in_array('enableDebugger', $config)) { | |
$configurator->enableDebugger(__DIR__ . '/../var/log'); | |
} | |
$configurator->setTempDirectory(__DIR__ . '/../var/temp'); | |
// define autoloader in composer.json, don't use RobotLoader | |
$configurator->addConfig(__DIR__ . '/config/config.neon'); | |
$configurator->addConfig(__DIR__ . '/config/parameters.neon'); | |
$container = $configurator->createContainer(); | |
convertPhpErrorsToExceptions(); | |
} | |
return $container; | |
} | |
function convertPhpErrorsToExceptions() | |
{ | |
set_error_handler('phpErrorToException'); | |
} | |
function phpErrorToException($severity, $message, $filename, $lineno) | |
{ | |
if (error_reporting() & $severity) { | |
throw new ErrorException($message, 0, $severity, $filename, $lineno); | |
} | |
} |
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
{ | |
"autoload": { | |
"psr-4": { | |
"App\\": ["app/console/", "app/model/", "app/presenters/", "app/router/"], | |
"Spider\\": "src/" | |
}, | |
"files": ["app/bootstrap.php"] | |
}, | |
"config": { | |
"bin-dir": "bin", | |
"optimize-autoloader": true | |
} | |
} |
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
#!/usr/bin/env php | |
<?php | |
// bin/console | |
clearCache(); | |
runNetteApp(); | |
/** | |
* Console always runs in production mode :( | |
* https://forum.nette.org/cs/7001-mode-a-environment-console-vs-production-vs-development | |
* Otherwise Nette\DI\MissingServiceException can be thrown in bin/console | |
* http://ci.edgedesign.cz:8080/job/EON_019/119/console | |
*/ | |
function clearCache() | |
{ | |
exec('(rm -rf var/temp) && (mkdir var/temp) && (touch var/temp/.gitkeep)'); | |
} | |
function runNetteApp() | |
{ | |
require __DIR__ . '/../vendor/autoload.php'; | |
getService('application')->run(); | |
} |
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
<?php | |
// www/index.php | |
require __DIR__ . '/../vendor/autoload.php'; | |
getService('application', ['enableDebugger'])->run(); |
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
<?php | |
// tests/bootstrap.php | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
function givenNetteService($service) | |
{ | |
return getService($service); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment