function testVirtualMethod() { echo "\ntesting calling a virtual method"; $argc = 1; $argv = array("argv"); $app = new MyApplication($argc, $argv); $myWidget = new MyWidget(); $myWidget->show(); $app->exec(); echo " passed"; }
*/ class MyApplication { private $_settings; private $_dbConnection; private $_dbQueryBuilder; private $_dbSchema; public function __construct($settings) { $this->_settings = $settings; switch ($this->_settings['dbDriver']) { case 'mysql': $factory = new MySQLFactory(); break; case 'oracle': $factory = new OracleFactory(); break; } $this->_dbConnection = $factory->createDBConnection(); $this->_dbQueryBuilder = $factory->createDBQueryBuilder(); $this->_dbSchema = $factory->createDBSchema(); } public function run() { $this->_dbConnection->getConnection(); $this->_dbQueryBuilder->getQuery(); $this->_dbSchema->getSchema(); } } $myApp = new MyApplication(array('dbDriver' => 'mysql')); $myApp->run();
<?php /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel, and is | the IoC container for the system binding all of the various parts. | */ // MyApplication is an extension of the provided application to modify sessions slightly $app = new MyApplication(); /* |-------------------------------------------------------------------------- | Detect The Application Environment |-------------------------------------------------------------------------- | | Laravel takes a dead simple approach to your application environments | so you can just specify a machine name for the host that matches a | given environment, then we will automatically detect it for you. | */ $env = $app->detectEnvironment(array('local' => array('homestead'))); /* |-------------------------------------------------------------------------- | Bind Paths |-------------------------------------------------------------------------- | | Here we are binding the paths configured in paths.php to the app. You
protected function viewForm() { // display form page $this->htmltemplate = 'form'; return true; } protected function viewData() { // display form page $this->htmltemplate = 'data'; // template name // usually it can be loaded from a Model $this->viewdata['data'] = array(array('name' => 'User1', 'email' => '*****@*****.**'), array('name' => 'User2', 'email' => '*****@*****.**'), array('name' => 'User3', 'email' => '*****@*****.**')); return true; } protected function beforeDisplay() { // set some extra information for any page if ($this->responseformat == 'html') { // only if this is html format to display if ($this->viewdata['message'] == '') { $this->viewdata['message'] = $this->router->getInput('message'); } $this->viewdata['applicationtitle'] = 'Demo application'; } return true; } } $application = MyApplication::getInstance(); $application->init(new appConfig(), $options); $application->action();
<?php class MyApplication extends \Silex\Application { use \Silex\Application\TwigTrait; } $app = new MyApplication(); $app['config'] = $config; $app['debug'] = $config['debug']; /* * Init Twig */ $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.options' => $config['twig.options'], 'twig.path' => $config['twig.path'])); /* * Init base de données */ $app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $config['db.options']));