Permalink
Browse files

Reordered docs with new features

  • Loading branch information...
wdalmut committed Dec 30, 2013
1 parent cc5058e commit 87ad7e733d215a4ea0f6f78bbe7e3c7fce089e69
Showing with 172 additions and 13 deletions.
  1. +15 −4 README.md
  2. +9 −5 docs/configuration.rst
  3. +89 −1 docs/controllers.rst
  4. +58 −2 docs/getting-started.rst
  5. +1 −1 src/UpCloo/App/Boot.php
View
@@ -37,9 +37,15 @@ $loader = include __DIR__ . '/vendor/autoload.php';
$loader->add("Your", __DIR__ . '/../src');
$conf = include __DIR__ . '/../configs/app.php';
$app = new \UpCloo\App([$conf]);
$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig(include __DIR__ . '/../configs/app.php');
$engine = new UpCloo\App\Engine();
$boot = new UpCloo\App\Boot($config);
$app = new UpCloo\App($engine, $boot);
$app->run();
```
Here is a config (configs/app.php)
@@ -68,7 +74,7 @@ return array(
),
"factories" => array(
"example" => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
return "that-service";
return "hello";
}
),
)
@@ -81,11 +87,16 @@ Start with a controller (src/Your/Controller/Name.php)
<?php
namespace Your\Controller;
use UpCloo\Controller\ServiceManager;
class Name
{
use ServiceManager;
public function hello()
{
return "world";
$hello = $this->services()->get("example");
return $hello . " " . "world";
}
}
```
View
@@ -72,18 +72,22 @@ Any `callable` hook is valid ::
Overload your configuration
---------------------------
You can pass to your `App` different configurations. The framework merge those
You can pass to your `Boot` different configurations. The framework merge those
together in order to obtain a single configuration.
This thing could be useful in order to obtain the right configuration for the
current environment.
For example see something like this: ::
$app = new \UpCloo\App([
include __DIR__ . '/../config/app.php',
include __DIR__ . "/../config/app.{$env}.php",
]);
$config = new \UpCloo\App\Config\ArrayProcessor();
$config->appendConfig(include __DIR__ . "/../configs/app.php");
$config->appendConfig(include __DIR__ . "/../configs/app.{$env}.php");
$boot = new \UpCloo\App\Boot($config);
...
In this way the conf loaded from `app.php` is overwritten by the second configuration
and so on. You can load how many conf you need.
View
@@ -122,14 +122,38 @@ the first argument is the redirect location.
The Redirector traits uses the "Response trait" by itself, for that reason when you use
the redirector the Response traits is automatically added to your controller.
ServiceManager
--------------
You can request anything from the service locator through just using the
`ServiceManager` trait. ::
<?php
namespace Your\NM;
use UpCloo\Controller\ServiceManager;
class TheHookContainer
{
use ServiceManager;
public function anHook()
{
$aService = $this->services()->get("a-service");
...
}
}
EventManager
------------
Inside an event you can attach and fire other events adding the EventManager
trait::
<?php
namespace Your\\NM;
namespace Your\NM;
use UpCloo\Controller\EventManager;
@@ -139,10 +163,74 @@ trait::
public function anHook()
{
// Attach something to an event
$this->events()->attach("finish", function() {
//Good bye cruel world!
});
// Trigger a custom event...
$this->events()->trigger("my.hook.event", $this, ["name" => "a name"]);
}
}
Test your controllers
---------------------
You can test your controller in isolation from the entire application, you have
just to prepare things that you need and inject into your controller.
See an example: ::
<?php
namespace Your\NM;
use UpCloo\Controller\EventManager;
class Controller
{
use EventManager;
public function myHook($event)
{
$this->events()->trigger("my.hook.start", $this);
... // do something...
$this->events()->trigger("my.hook.finish", $this, $data);
return $data;
}
}
Your tests could be something like this: ::
<?php
namespace UpCloo\NM;
use Zend\EventManager\EventManager;
use UpCloo\Test\ControllerTestUtils;
class ControllerTest extends \PHPUnit_Framework_TestCase
{
use ControllerTestUtils;
private $object;
public function setUp()
{
// Prepare the controller
$this->object = new Controller();
$this->object->setEventManager(new EventManager());
}
public function testWorkingAction()
{
$event = $this->getEventFromParams([
"param" => "hello"
]);
$data = $this->object->myHook($event);
// asserts on data
}
}
View
@@ -3,7 +3,7 @@ Getting Started with UpCloo Framework
The base folder structure is: whatever you want...
I suggest something like this: ::
We suggest something like this: ::
- configs
- src
@@ -34,7 +34,14 @@ the `index.php` file. ::
$loader->add("My", __DIR__ . '/../src');
$conf = include __DIR__ . "/../configs/app.php";
$app = new \UpCloo\App([$conf]);
$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig($conf);
$boot = new UpCloo\App\Boot($config);
$engine = new UpCloo\App\Engine();
$app = new UpCloo\App($engine, $boot);
$app->run();
As you can see the first to line uses the composer autoloader in order to
@@ -155,3 +162,52 @@ The output should be something similar to this: ::
Now you can continue with more interesting things!
Integration testing
-------------------
You can test your controller in isolation (see :doc:`controllers`) or you can
run the whole application. If you are interested in this last thing, you have
to inherits from `UpCloo\Test\WebTestCase` during testing. ::
<?php
namespace Your\NM;
use UpCloo\Test\WebTestCase;
class MyControllerTest extends WebTestCase
{
public function setUp()
{
$this->appendConfig([
"router" => [
... // Routes
],
"services" => [
... // A conf
],
...
]);
}
public function testMyAction()
{
$response = $this->dispatch("/my-action"); //get method
$this->assertEquals(200, $response->getStatusCode());
//... more assert
$content = $response->getContent();
//...
}
}
The `dispatch` method signature is: ::
public function dispatch($url, $method = "GET", array $params = array())
Possibile methods are:
* GET
* POST
* PUT
View
@@ -1,8 +1,8 @@
<?php
namespace UpCloo\App;
use Zend\ServiceManager\ServiceManager;
use Zend\EventManager\EventManager;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config as ServiceManagerConfig;
class Boot

0 comments on commit 87ad7e7

Please sign in to comment.