mamuz/phalcon-application
Composer 安装命令:
composer require mamuz/phalcon-application
包简介
Phalcon Application provides simple and customizable application bootstrapping
关键字:
README 文档
README
Phalcon Application is built on top of Phalcon3 Framework and provides simple and customizable application bootstrapping.
Requirements
- Phalcon3 is needed, follow install steps at https://github.com/phalcon/cphalcon
Installation
Install the latest version with
$ 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.
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.
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).
Like this:
<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.
For instance you have a controller with two actions like:
User::loginActionUser::logoutAction
This leads to two view templates located at:
{viewbasepath}\user\login.phtml{viewbasepath}\user\logout.phtml
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)
In case of ajax requests (XHR) outerframe and frame rendering is disabled, which means only the innerframe is rendered.
$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.
Bootstrapping an application as a command line tool
Check https://docs.phalconphp.com/en/latest/reference/cli.html#tasks for creating tasks.
$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
$ php index.php mailing send reminder
That will call the send action from the mailing task with invoking reminder as an argument.
Run a command with arguments and options
Let's imagine that the application is bootstrapped inside index.php
$ 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().
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.
Application Skeleton
To have a good starting place you should check the skeleton which is based on this project.
mamuz/phalcon-application 适用场景与选型建议
mamuz/phalcon-application 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.73k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2015 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「application」 「phalcon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mamuz/phalcon-application 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mamuz/phalcon-application 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mamuz/phalcon-application 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
A Laravel queue connector to process jobs at the end of the application
Uniondrug Trace Client Component for uniondrug/framework
C3JS By phpanonymous (Mahmoud Ibrahim)
Библиотека для работы с BigQuery
This package manage your site basic settings like - site title, logo etc. You can also add your custom setting using this package.
统计信息
- 总下载量: 7.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-16