Skip to content

Releases: simplemvc/framework

Release 0.3.0

13 Sep 20:56
0.3.0
39ed176
Compare
Choose a tag to compare

This is the 0.3.0 release of SimpleMVC framework.

This release includes the following fixes and addition:

  • Fixed the controller pipeline routing, using an array of controllers in the route #2
  • Added the AttributeInterface and AttributeTrait for passing attributes between controllers in a pipeline #2

Now you can pass PSR-7 attributes to $request between controllers using the addRequestAttribute() function of AttributeInterface. For instance, if you have a [Controller\A::class, Controller\B:class] route pipeline, you can pass a foo attribute between A and B controller as follows:

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SimpleMVC\Controller\AttributeInterface;
use SimpleMVC\Controller\AttributeTrait;
use SimpleMVC\Controller\ControllerInterface;

class A implements ControllerInterface, AttributeInterface
{
    use AttributeTrait;

    public function execute(
        ServerRequestInterface $request, 
        ResponseInterface $response
    ): ResponseInterface
    {
        $this->addRequestAttribute('foo', 'bar');
        return $response;
    }
}

In order to get the foo parameter in the B controller you can use the PSR-7 standard function getAttribute() from the HTTP request, as follows:

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SimpleMVC\Controller\ControllerInterface;

class B implements ControllerInterface
{
    public function execute(
        ServerRequestInterface $request, 
        ResponseInterface $response
    ): ResponseInterface
    {
        $attribute = $request->getAttribute('foo');
        pritnf("Attribute is: %s", $attribute); // bar
        return $response;
    }
}

Note that you don't need to implement the AttributeInterface for the B controller since we only need to read from the $request.

A special thanks to @danielebarbaro for helping in this release!

Release 0.2.0

17 Aug 16:51
0.2.0
fdd2998
Compare
Choose a tag to compare

This is the 0.2.0 release of SimpleMVC framework.

This release includes the following changes and addition:

  • Simplified the configuration of SimpleMVC\App using only one config key in the container. See #1 for more information
  • Added the SimpleMVC\Controller\RouteTrait to route request using the HTTP methods (GET, POST, PUT, etc) inside a Controller. See simplemvc/skeleton#3 for more information.

The RouteTrait can be useful if you need to route the request into specific functions inside the same Controller (eg. for building a REST API). These functions are named as the HTTP method. For instance, if you have a route like this:

[['GET', 'POST'], '/login', Controller\Login::class]

You can than use the RouteTrait as follows in Controller\Login.

namespace App\Controller\Login;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SimpleMVC\Controller\ControllerInterface;
use SimpleMVC\Controller\RouteTrait;

class Login implements ControllerInterface
{
    use RouteTrait;

    public function get(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        // @todo manage the GET request
    }
    public function post(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        // @todo manage the POST request
    }
}

A special thanks to @danielebarbaro and @adamculp for the help in this release!

Release 0.1

25 Jul 13:45
0.1
333d2e0
Compare
Choose a tag to compare

This is the first release 0.1 of SimpleMVC framework for PHP applications 🥳