PHPackages                             aferalabs/phalcon-expressive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. aferalabs/phalcon-expressive

ActiveProject[Framework](/categories/framework)

aferalabs/phalcon-expressive
============================

031PHP

Since Dec 28Pushed 10y ago2 watchersCompare

[ Source](https://github.com/theDisco/phalcon-expressive)[ Packagist](https://packagist.org/packages/aferalabs/phalcon-expressive)[ RSS](/packages/aferalabs-phalcon-expressive/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Phalcon 2 integration for Zend Expressive
=========================================

[](#phalcon-2-integration-for-zend-expressive)

[![Build Status](https://camo.githubusercontent.com/e639ce88f8dd97ed46b4f95cca04337c2f8cf956db70ea52a8b209345a28830d/68747470733a2f2f7472617669732d63692e6f72672f746865446973636f2f7068616c636f6e2d657870726573736976652e737667)](https://travis-ci.org/theDisco/phalcon-expressive)

This project is supposed to provide a bridge between Zend Expressive and Phalcon Framework. It is partially tested but it might still include a lot of bugs, therefore do not consider it as production ready.

Installation
============

[](#installation)

This step is optional but suggested to kick start your new project. Use Zend Expressive skeleton by running the command below, to create a suggested project structure.

```
$ composer create-project zendframework/zend-expressive-skeleton

```

When asked to select the router, type:

```
aferalabs/phalcon-expressive:dev-master

```

When asked to select DI container, type:

```
aferalabs/phalcon-expressive:dev-master

```

Phalcon Router
==============

[](#phalcon-router)

Creation of a router boils down to this simple lines:

```
use PhalconExpressive\PhalconRouter;

$router = new PhalconRouter;
```

`PhalconExpressive\PhalconRouter` depends on `Phalcon\Mvc\Router` and `Phalcon\Mvc\Url`. If you want to provide alternative instances of these services, you might do so by passing them as constructor arguments. Otherwise they will be created using default values.

```
use Phalcon\Mvc;
use PhalconExpressive\PhalconRouter;
use Zend\Expressive\AppFactory;

$url = new Mvc\Url;
$url->setBaseUri('/blog');

$router = new Mvc\Router;
$router->setEventsManager(new Phalcon\Events\Manager);

$router = new PhalconRouter(null, $url);
$app = AppFactory::create(null, $router);
```

The simplest way to integrate the Phalcon router is to define it in invokable dependencies in the routes config:

```
return [
    'dependencies' => [
        'invokables' => [
            Zend\Expressive\Router\RouterInterface::class => PhalconExpressive\PhalconRouter::class,
        ],
    ],
    'routes' => [
        [
            'name' => 'home',
            'path' => '/',
            'middleware' => App\Action\HomePageAction::class,
            'allowed_methods' => ['GET'],
        ],
        [
            'name' => 'api.ping',
            'path' => '/api/ping',
            'middleware' => App\Action\PingAction::class,
            'allowed_methods' => ['GET'],
        ],
    ],
];
```

Phalcon DI
==========

[](#phalcon-di)

Phalcon Expressive includes an implementation of `Interop\Container\ContainerInterface` that is build on top of `Phalcon\DI`. In order to set up the container, create a new file `config/container.php`and add following content to it:

```
