-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from mruz/master
Add Ice framework 1.0
- Loading branch information
Showing
9 changed files
with
110 additions
and
1 deletion.
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
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,48 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
/** | ||
* Register the psr-4 auto loader. You will be able to use: | ||
* App\Controller, App\Model, App\Library, etc. | ||
*/ | ||
(new \Ice\Loader()) | ||
->addNamespace(__NAMESPACE__, __DIR__) | ||
->register(); | ||
|
||
// Create a dependency injector container | ||
$di = new \Ice\Di(); | ||
|
||
// Set some services | ||
$di->request = new \Ice\Http\Request(); | ||
$di->response = new \Ice\Http\Response(); | ||
$di->tag = new \Ice\Tag(); | ||
|
||
$di->set('dispatcher', function () { | ||
$dispatcher = new \Ice\Mvc\Dispatcher(); | ||
$dispatcher->setNamespace(__NAMESPACE__); | ||
|
||
return $dispatcher; | ||
}); | ||
|
||
$di->set('router', function () { | ||
$router = new \Ice\Mvc\Router(); | ||
$router->setRoutes([ | ||
// The default routes | ||
['GET', '/{controller:[a-z]+}/{action:[a-z]+[/]?}'], | ||
['GET', '/{controller:[a-z]+[/]?}'], | ||
['GET', ''], | ||
]); | ||
|
||
return $router; | ||
}); | ||
|
||
$di->set('view', function () { | ||
$view = new \Ice\Mvc\View(); | ||
$view->setViewsDir(__DIR__ . '/View/'); | ||
|
||
return $view; | ||
}); | ||
|
||
// Create and return a MVC application | ||
return new \Ice\Mvc\App($di); |
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,12 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
class HelloController extends IndexController | ||
{ | ||
|
||
public function indexAction() | ||
{ | ||
$this->view->setContent('Hello World!'); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use Ice\Mvc\Controller; | ||
|
||
class IndexController extends Controller | ||
{ | ||
|
||
public function indexAction() | ||
{ | ||
|
||
} | ||
} |
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 @@ | ||
index |
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 @@ | ||
<?php echo $this->getContent() ?> |
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,9 @@ | ||
#/public/.htaccess | ||
Options FollowSymLinks | ||
<IfModule mod_rewrite.c> | ||
RewriteEngine On | ||
|
||
RewriteCond %{REQUEST_FILENAME} !-d | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] | ||
</IfModule> |
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,20 @@ | ||
<?php | ||
|
||
error_reporting(E_ALL); | ||
|
||
try { | ||
// Load the bootstrap which return the MVC application | ||
$app = require_once __DIR__ . '/../App/Bootstrap.php'; | ||
|
||
// Handle a MVC request and display the HTTP response body | ||
echo $app->handle(); | ||
} catch (Exception $e) { | ||
// Dispaly the excepton's message | ||
echo $e->getMessage(); | ||
} | ||
|
||
printf( | ||
"\n%' 8d:%f", | ||
memory_get_peak_usage(true), | ||
microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'] | ||
); |