2017 © Pedro Peláez
 

library phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

image

mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  • Monday, November 28, 2016
  • by mamuz
  • Repository
  • 4 Watchers
  • 11 Stars
  • 3,395 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 21 Versions
  • 2 % Grown

The README.md

phalcon-application

Author Build Status Latest Stable Version Total Downloads License, (*1)

Phalcon Application is built on top of Phalcon3 Framework and provides simple and customizable application bootstrapping., (*2)

Requirements

  • Phalcon3 is needed, follow install steps at https://github.com/phalcon/cphalcon

Installation

Install the latest version with, (*3)

$ composer require mamuz/phalcon-application

Features

  • Autoloading with Composer
  • Simple mvc configuration
  • Service registration
  • XHR friendly view renderer

Usage

Bootstrapping an application without view support, e.g. a REST application

$config = [
    'dispatcher' => [
        // define class namespace identifier of your controllers
        'controllerDefaultNamespace' => 'Rest\Controller',
    ],
    'routes' => [
        // see Router::add in https://docs.phalconphp.com/en/latest/reference/routing.html
        'default' => [
            'pattern'     => '/:controller/:action',
            'paths'       => ['controller' => 1, 'action' => 2], // Optional
            'httpMethods' => ['GET'], // Optional
            'position'    => 1, // Optional
        ],
    ],
    // register custom service factories implementing the InjectableInterface
    // see: https://github.com/mamuz/phalcon-application/blob/master/src/Application/Service/InjectableInterface.php
    // Key is the name to refer to Phalcon's DI, value is the FQCN of the service factory
    'services' => [
        'user'   => 'User\Service\Factory',
        'logger' => 'Logger\Service\Factory',
    ],
];

// make everything relative to the application root
chdir(dirname(__DIR__));

// Composer Autoloader (see: https://getcomposer.org/doc/01-basic-usage.md#autoloading)
include './vendor/autoload.php';

// bootstrap and run your application
Phapp\Application\Bootstrap::init($config)->runApplicationOn($_SERVER);

For more details have a look to the functional tests at https://github.com/mamuz/phalcon-application/blob/master/tests/functional/ActionDomainResponseCest.php based on that example project., (*4)

Bootstrapping an application with view support (mostly to response with rendered HTML)

Check https://docs.phalconphp.com/en/latest/reference/views.html for using views in Phalcon., (*5)

Phalcon's view engine supports the three-step view template pattern. That means you can have a main-layout (outerframe), which includes a controller based layout (frame), which in turn includes an action based layout (innerframe)., (*6)

Like this:, (*7)

<outerframe>
    I am the main layout.
    <frame>
        I am the controller based layout.
        <innerframe>
            I am the action based layout.
        </innerframe>
    </frame>
</outerframe>

So each controller action can have an own template for rendering., (*8)

For instance you have a controller with two actions like: - User::loginAction - User::logoutAction, (*9)

This leads to two view templates located at: - {viewbasepath}\user\login.phtml - {viewbasepath}\user\logout.phtml, (*10)

Regarding the three-step view template pattern you can place these ones at: - {viewbasepath}\index.phtml (outerframe must be named as index and needs to be placed at the root level) - {viewbasepath}\layouts\user.phtml (frame must be named like the controller and needs to be placed inside layouts folder), (*11)

In case of ajax requests (XHR) outerframe and frame rendering is disabled, which means only the innerframe is rendered., (*12)

$config = [
    'dispatcher' => [
        // define class namespace identifier of your controllers
        'controllerDefaultNamespace' => 'Mvc\Controller',
    ],
    'routes' => [
        // see Router::add in https://docs.phalconphp.com/en/latest/reference/routing.html
        'default' => [
            'pattern'     => '/:controller/:action',
            'paths'       => ['controller' => 1, 'action' => 2], // Optional
            'httpMethods' => ['GET'], // Optional
            'position'    => 1, // Optional
        ],
    ],
    // register custom service factories implementing the InjectableInterface
    // see: https://github.com/mamuz/phalcon-application/blob/master/src/Application/Service/InjectableInterface.php
    // Key is the name to refer to Phalcon's DI, value is the FQCN of the service factory
    'services' => [
        'user'   => 'User\Service\Factory',
        'logger' => 'Logger\Service\Factory',
    ],
    // declare the basepath for the view templates, which enables Phalcon's view engine
    'view' => [
        'templatePath' => './view',
    ],
];

// make everything relative to the application root
chdir(dirname(__DIR__));

// Composer Autoloader (see: https://getcomposer.org/doc/01-basic-usage.md#autoloading)
include './vendor/autoload.php';

// bootstrap and run your application
Phapp\Application\Bootstrap::init($config)->runApplicationOn($_SERVER);

For more details have a look to the functional tests at https://github.com/mamuz/phalcon-application/blob/master/tests/functional/ViewCest.php based on that example project., (*13)

Bootstrapping an application as a command line tool

Check https://docs.phalconphp.com/en/latest/reference/cli.html#tasks for creating tasks., (*14)

$config = [
    'dispatcher' => [
        // define class namespace identifier of your tasks
        'taskDefaultNamespace' => 'Command\Task',
    ],
    // register custom service factories implementing the InjectableInterface
    // see: https://github.com/mamuz/phalcon-application/blob/master/src/Application/Service/InjectableInterface.php
    // Key is the name to refer to Phalcon's DI, value is the FQCN of the related service factory
    'services' => [
        'user'   => 'User\Service\Factory',
        'logger' => 'Logger\Service\Factory',
    ],
];

// make everything relative to the application root
chdir(dirname(__DIR__));

// Composer Autoloader (see: https://getcomposer.org/doc/01-basic-usage.md#autoloading)
include './vendor/autoload.php';

// bootstrap and run your application
Phapp\Application\Bootstrap::init($config)->runApplicationOn($_SERVER);

Run a command with arguments

Let's imagine that the application is bootstrapped inside index.php, (*15)

$ php index.php mailing send reminder

That will call the send action from the mailing task with invoking reminder as an argument., (*16)

Run a command with arguments and options

Let's imagine that the application is bootstrapped inside index.php, (*17)

$ php index.php mailing send reminder --sender=foo@bar.com --bcc=baz@bar.com

That will call the send action from the mailing task with invoking reminder as an argument. Inside the send action the options are aware by $this->dispatcher->getOptions()., (*18)

For more details have a look to the functional tests at https://github.com/mamuz/phalcon-application/blob/master/tests/functional/CommandLineCest.php based on that example project., (*19)

Application Skeleton

To have a good starting place you should check the skeleton which is based on this project., (*20)

The Versions

28/11 2016

dev-reactive

dev-reactive https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php ^7.0
  • ext-phalcon ^3.0

 

The Development Requires

by Marco Muths

application phalcon

18/10 2016

dev-master

9999999-dev https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • ext-phalcon ^3.0
  • php ^7.0

 

The Development Requires

by Marco Muths

application phalcon

18/10 2016

v2.2.1

2.2.1.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php ^7.0
  • ext-phalcon ^3.0

 

The Development Requires

by Marco Muths

application phalcon

02/10 2016

v2.2.0

2.2.0.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php ^7.0
  • ext-phalcon ^3.0

 

The Development Requires

by Marco Muths

application phalcon

26/09 2016

v2.1.0

2.1.0.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php ^7.0
  • ext-phalcon ^3.0

 

The Development Requires

by Marco Muths

application phalcon

13/09 2016

v2.0.0

2.0.0.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-phalcon ^3.0

 

The Development Requires

by Marco Muths

application phalcon

13/09 2016

v1.0.4

1.0.4.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon ^2.0.0

 

The Development Requires

by Marco Muths

application phalcon

13/09 2016

v1.0.3

1.0.3.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon ^2.0.0

 

The Development Requires

by Marco Muths

application phalcon

12/09 2016

v1.0.2

1.0.2.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon ^2.0.0

 

The Development Requires

by Marco Muths

application phalcon

11/09 2016

v1.0.1

1.0.1.0 https://github.com/mamuz/phalcon-application

Phalcon Application provides simple and customizable application bootstrapping

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

08/06 2016

v1.0.0

1.0.0.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

11/04 2016

v0.1.9

0.1.9.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

16/02 2016

v0.1.8

0.1.8.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

03/02 2016

v0.1.7

0.1.7.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

26/08 2015

v0.1.6

0.1.6.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

18/08 2015

v0.1.5

0.1.5.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

17/08 2015

v0.1.4

0.1.4.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

17/08 2015

v0.1.3

0.1.3.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

17/08 2015

v0.1.2

0.1.2.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

16/08 2015

v0.1.1

0.1.1.0 https://github.com/mamuz/phalcon-application

Phalcon Application is built on top of Phalcon2 and simplifies Bootstrapping and Registering Controllers & Tasks.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon

16/08 2015

v0.1.0

0.1.0.0 https://github.com/mamuz/phalcon-application

project description

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-phalcon >=2.0.0

 

The Development Requires

by Marco Muths

application phalcon