Introduction to
Monsoon PHP Framework
(monsoonphp.com)
Made in Bhārat
Learning Agenda
‱ Getting Started
‱ App, Api and Cli
‱ The Box
‱ Framework Internals
‱ Tools
Introduction to Monsoon Framework
‱ HMVC Pattern in PHP
‱ App, API and CLI scripts in one codebase
‱ Composer compatible (bring your own library)
‱ Docker ready
‱ Ready with essential tools
‱ PHP Unit, PHP Code Sniffer, PHP Mess Detector
‱ Open source and extensible
Who can use?
‱ Senior and Junior PHP developers
‱ Architects who want a fast, secure and performing code structure
‱ Students who want to understand MVC implementation in PHP
‱ Seasoned application developers
‱ Any PHP Programmer
Why Monsoon?
Monsoon is the framework for you, if
‱ you love core PHP and simple MVC, not a creative vocabulary
‱ you love HTML in view files, not any template engines
‱ you love plain SQL queries in the models, not objects
‱ you love automatic routing in your application, not a rule to define each route
‱ you want to take control of the entire script execution cycle, not some black box
‱ you need a light-weight and secure structure, not an extra-terrestrial folder structure
Kick Start
Just 2 steps to kick start
‱ Step – 1 : Get the code through Composer
‱ composer create-project monsoon/framework .
‱ Step – 2 : Start the webserver
‱ php –S localhost:8080 -t public/
Folder Structure
Top level
‱ src
‱ App
‱ Api
‱ Cli
‱ Config
‱ Framework
‱ bin
‱ data
‱ public
‱ resources
App/
‱ Classes
‱ Controllers
‱ Entities
‱ Factories
‱ Helpers
‱ Interfaces
‱ Layouts
‱ Models
‱ Modules/
‱ Tests
‱ Traits
‱ views
Modules/
‱ Controllers
‱ Models
‱ views
Note
‱ Api, App, Cli, Config, Framework folder names have the first
letter in uppercase, as they contain classes and need to be
PSR-4 compliant
‱ src, views, bin, data, resources, public folders are in lower
case
Api/
‱ Services
‱ Tests
Config/
‱ Config.php
‱ .env.php
‱ .routes.php
Folder Structure (cont.)
data/
‱ cache
‱ conf
‱ docker
‱ locale
‱ logs
‱ migrations
‱ schema
‱ storage
‱ uploads
resources/
‱ css
‱ fonts
‱ img
‱ js
‱ less
public/
‱ css
‱ files
‱ fonts
‱ img
‱ js
Execution Flow
‱ Starts from public/index.php
‱ Calls src/App/Classes/Initialize.php
‱ Loads configuration from
‱ Config/Config.php
‱ Config/.env.php
‱ Config/.routes.php
‱ Automatically invokes your Controller based on the url or route defined
‱ Your Controller invokes your Models/Entities
‱ Renders HTML from your view file
‱ Done !!
URL Routing
Automatic routing
‱ /
‱ src/App/Controllers/IndexController.php : indexAction()
‱ /forgot-password
‱ src/App/Controllers/ForgotPasswordController.php : indexAction()
or
‱ src/App/Modules/ForgotPassword/Controllers/IndexController.php : indexAction()
‱ /account/forgot-password
‱ src/App/Controllers/AccountController.php : forgotPasswordAction()
‱ or
‱ src/App/Modules/Account/ForgotPasswordController.php : indexAction()
‱ /settings/users/edit/23
‱ src/App/Modules/Settings/Controllers/UsersController.php : editAction(23)
URL Routing (cont.)
Manual routing
‱ defined in src/App/Config/.routes.php
‱ Example
‱ ”login/(:any)” => “ControllersAccountController@loginAction”
Configuration Files
‱ Application configuration
‱ src/Config/Config.php
‱ src/Config/.env.php and src/Config/.routes.php
‱ composer.json – Composer configuration
‱ package.json – NPM package configuration
‱ docker-compose.yml – Docker configuration
‱ Supported by data/docker/Dockerfile
‱ gulpfile.js – For Gulp tasks
‱ phinx.php – Handling database migrations
‱ Migrations will be created in data/migrations/
‱ phpcs.xml – PHP Coding Standards Ruleset
‱ phpmd.xml – PHP Mess Detector Ruleset
‱ phpunit.xml – PHP Unit configuration file
ConfigVariables
‱ Config.php
‱ BASE_URL constant
‱ application
‱ title, url, layout, timezone, uploadMaxFileSize, email, language
‱ env (loaded from .env.php)
‱ name, errorReporting, profiler,
‱ encryptionKey, pepperKey
‱ database (type, hostname, port, database, username, password)
‱ smtp (hostname, port, username, password)
‱ routes (from .routes.php)
The “Box”
‱ A class just to hold information
‱ Contains
‱ $data
‱ $identity
‱ $config
‱ $container
‱ .. and variables assigned by you
‱ Accessible across all classes in a static way
‱ Box::$data[‘usersList’]
‱ “Just put it in the box”
Controllers
src/App/Controllers/UsersController.php
<?php
namespace Controllers;
use FrameworkBox;
class UsersController extends FrameworkController
{
public function indexAction()
{
// 

Box::$data[‘username’] = ‘Krishna’;
View::renderDefault(‘users/index’);
}
private function internalMethod()
{
// 

}
}
Models
src/App/Models/UsersModel.php
<?php
namespace Models;
class UsersModel extends FrameworkModel
{
public function getUserDetails($userId)
{
$sql = ‘SELECT user_name, email_id, designation FROM usersWHERE user_id = ?’;
$params = [$userId];
$this->sql($sql, $params);
return $this->db->result->rows[0];
}
}
Views (.phtml)
src/App/views/users/index.phtml
<?php
use FrameworkBox;
?>


<div class=“container”>
<h5>Welcome <?=Box::$data[‘username’]; ?>!! </h5>
<p>You have earned <?=Box::getData(‘userPoints’); ?> in your score card.</p>
</div>


Layouts
‱ Layout must have header.phtml and footer.phtml under
src/App/Layouts/<layout_name> folder
‱ ”default” layout is used by default
‱ Can be invoked from Controller
‱ View::renderDefault(‘users/index’);
‱ View::render(‘users/index’, ‘custom-layout’);
‱ Box’ed data can be used in the Layout
Modules
‱ Modules within your application for HMVC pattern
‱ Sets of Controllers, Models, views
‱ You can also add Interfaces, Helpers, Classes, etc.
‱ PSR-4 compliant
‱ Separate namespace
‱ e.g. namespace ModulesSettingsControllers;
Entities
src/App/Entities/User.php
<?php
namespace Entities;
class User extends FrameworkEntity
{
public function __construct()
{
parent::__construct();
$this->setTableName(‘users’);
$this->setIdField(‘user_id’);
}
}
Usage
$user = new EntitiesUser();
$user->first_name = ‘Krishna’;
$user->last_name = ‘Manda’;
$user->email_id = ‘krishna@example.com’;
$user->save();
// 

echo ‘User Id : ‘.$user->user_id;
Framework/
‱ Application
‱ BootstrapUI
‱ Box
‱ Captcha
‱ Cipher
‱ Config
‱ Container
‱ Controller
‱ Curl
‱ Database
‱ Datagrid
‱ Datasource
‱ Entity
‱ Error
‱ Html
‱ Identity
‱ Locale
‱ Logger
‱ Model
‱ Profiler
‱ Request
‱ Response
‱ Router
‱ Security
‱ Service
‱ Session
‱ Utilities
‱ Validator
‱ View
‱ Watchlist
FrameworkSecurity
‱ Security::forceHttps()
‱ Security::setSecureHeaders()
‱ Security::generateSalt(), Security::generateGUID()
‱ Security::generateCSRFToken(), Security::isCSRFTokenValid()
‱ Security::escapeSql()
‱ Security::escapeXSS()
‱ Security::stripTagsContent()
‱ Security::generatePassword()
‱ 
 and more
APIs
‱ File name suffixed with ”Service.php”
‱ Similar to App/Controllers have “Controller.php” suffix
‱ Methods in Service are suffixed with “Action” word
‱ App/Controllers also use “Action”
‱ Methods in Service are prefixed with HTTP method
‱ public function getUserOperation($id)
‱ public function postUserOperation($userData)
‱ public function patchUserOperation($changedUserData)
API Example
src/Api/Services/UsersService.php
<?php
namespace ApiServices;
use ModelsUsersModel;
class UsersService extends FrameworkService
{
public function getUserOperation($userId)
{
$userData = (new UsersModel)->getUserDetails($userId);
$response = new FrameworkResponse();
$response->setHttpStatusCode('200', 'OK’);
$response->setData($userData);
$response->dispatchJson();
}
}
CLI Programming
‱ Use the popular Symfony’s Console component
(https://symfony.com/doc/current/components/console.html)
‱ Triggering scripts from bin/
‱ Classes in Cli/
‱ Flow
‱ Create class in Cli/ and include them in bin/console
‱ Running from terminal, an example
‱ $ php bin/console greet Krishna
Dependency Injection (Factory Pattern)
src/App/Factories/IndexControllerFactory.php
<?php
namespace Factories;
use ConfigConfig,
use ControllersIndexController;
use FrameworkContainer;
use FrameworkInterfacesFactoryInterface;
class IndexControllerFactory implements FactoryInterface
{
public static function create(Container $container)
{
return new IndexController($container->get(Config::class));
}
}
src/App/Controllers/IndexController.php
<?php
namespace Controllers;
class IndexController extends FrameworkController
{
public function __construct(Config $config)
{
$this->config = $config;
}
public function indexAction()
{
// ...
}
}
Database Migrations
‱ Phinx based migrations (http://docs.phinx.org/en/latest/)
‱ phinx.php – Configuration file
‱ Migration commands
‱ vendor/bin/phinx create MyNewMigration
‱ vendor/bin/phinx migrate
‱ Migrations are created under data/migrations
WritingTest Cases
‱ Support for PHPUnit (https://phpunit.readthedocs.io/en/8.2/)
‱ Test cases maintained under
‱ src/App/Tests
‱ src/App/Modules/<module_name>/Tests
‱ src/Api/Tests
‱ Commands
‱ vendor/bin/phpunit
Thank you!
‱ Try MonsoonPHP with a small POC
‱ Visit Monsoon PHP website for more video tutorials
‱ https://monsoonphp.com

More Related Content

PDF
Fixin Framework
PDF
Json api dos and dont's
PDF
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
PPTX
Content Modeling Behavior
PDF
Doing Drupal security right
PDF
Life outside WO
PDF
Unsafe JAX-RS: Breaking REST API
PPTX
Apache Solr-Webinar
Fixin Framework
Json api dos and dont's
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Content Modeling Behavior
Doing Drupal security right
Life outside WO
Unsafe JAX-RS: Breaking REST API
Apache Solr-Webinar

What's hot (19)

PPTX
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
PDF
Intro apache
PDF
In memory OLAP engine
PDF
Building a spa_in_30min
PDF
D2W Stateful Controllers
PDF
Codeigniter
ZIP
Rails 3 (beta) Roundup
PDF
Unit Testing with WOUnit
PPTX
Php reports sumit
PDF
Basics of Solr and Solr Integration with AEM6
PDF
Andrei shakirin rest_cxf
PPTX
Java server pages
PPTX
Amp and higher computing science
PPTX
Enterprise Search Using Apache Solr
PPT
SQL injection basics
PDF
YiiConf 2012 - Alexander Makarov - Yii2, what's new
PDF
Entity provider selection confusion attacks in JAX-RS applications
PDF
symfony_from_scratch
KEY
Asset Pipeline
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
Intro apache
In memory OLAP engine
Building a spa_in_30min
D2W Stateful Controllers
Codeigniter
Rails 3 (beta) Roundup
Unit Testing with WOUnit
Php reports sumit
Basics of Solr and Solr Integration with AEM6
Andrei shakirin rest_cxf
Java server pages
Amp and higher computing science
Enterprise Search Using Apache Solr
SQL injection basics
YiiConf 2012 - Alexander Makarov - Yii2, what's new
Entity provider selection confusion attacks in JAX-RS applications
symfony_from_scratch
Asset Pipeline
Ad

Similar to Introduction to Monsoon PHP framework (20)

KEY
Future of PHP
PDF
SDPHP Lightning Talk - Let's Talk Laravel
PDF
Streamlining Your Applications with Web Frameworks
PPTX
Introduction to Laravel Framework (5.2)
PPTX
They why behind php frameworks
PDF
Web Services PHP Tutorial
PDF
Intro To Mvc Development In Php
PDF
More about PHP
PPTX
Software Development with PHP & Laravel
PPTX
Codeigniter
PDF
Web services tutorial
PDF
Web Services Tutorial
PPTX
4. Web programming MVC.pptx
PPTX
Day02 a pi.
PDF
Yii2 guide
PPT
Web service with Laravel
PDF
Lecture11_LaravelGetStarted_SPring2023.pdf
PDF
Build powerfull and smart web applications with Symfony2
PPTX
Lecture 2_ Intro to laravel.pptx
PDF
Building Lithium Apps
Future of PHP
SDPHP Lightning Talk - Let's Talk Laravel
Streamlining Your Applications with Web Frameworks
Introduction to Laravel Framework (5.2)
They why behind php frameworks
Web Services PHP Tutorial
Intro To Mvc Development In Php
More about PHP
Software Development with PHP & Laravel
Codeigniter
Web services tutorial
Web Services Tutorial
4. Web programming MVC.pptx
Day02 a pi.
Yii2 guide
Web service with Laravel
Lecture11_LaravelGetStarted_SPring2023.pdf
Build powerfull and smart web applications with Symfony2
Lecture 2_ Intro to laravel.pptx
Building Lithium Apps
Ad

Recently uploaded (20)

PDF
Canva Desktop App With Crack Free Download 2025?
PDF
IObit Driver Booster Pro Crack Latest Version Download
PDF
IDM Crack Activation Key 2025 Free Download
PPTX
Greedy best-first search algorithm always selects the path which appears best...
PPTX
MCP empowers AI Agents from Zero to Production
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PPTX
oracle_ebs_12.2_project_cutoveroutage.pptx
PDF
10 Mistakes Agile Project Managers Still Make
PDF
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
PDF
C language slides for c programming book by ANSI
PDF
OpenEXR Virtual Town Hall - August 2025
PPTX
ESDS_SAP Application Cloud Offerings.pptx
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
 
PDF
How to Set Realistic Project Milestones and Deadlines
PPT
chapter01_java_programming_object_oriented
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
PDF
Top AI Tools for Project Managers: My 2025 AI Stack
PDF
How to Write Automated Test Scripts Using Selenium.pdf
Canva Desktop App With Crack Free Download 2025?
IObit Driver Booster Pro Crack Latest Version Download
IDM Crack Activation Key 2025 Free Download
Greedy best-first search algorithm always selects the path which appears best...
MCP empowers AI Agents from Zero to Production
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
oracle_ebs_12.2_project_cutoveroutage.pptx
10 Mistakes Agile Project Managers Still Make
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
C language slides for c programming book by ANSI
OpenEXR Virtual Town Hall - August 2025
ESDS_SAP Application Cloud Offerings.pptx
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
 
How to Set Realistic Project Milestones and Deadlines
chapter01_java_programming_object_oriented
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Top AI Tools for Project Managers: My 2025 AI Stack
How to Write Automated Test Scripts Using Selenium.pdf

Introduction to Monsoon PHP framework

  • 1. Introduction to Monsoon PHP Framework (monsoonphp.com) Made in Bhārat
  • 2. Learning Agenda ‱ Getting Started ‱ App, Api and Cli ‱ The Box ‱ Framework Internals ‱ Tools
  • 3. Introduction to Monsoon Framework ‱ HMVC Pattern in PHP ‱ App, API and CLI scripts in one codebase ‱ Composer compatible (bring your own library) ‱ Docker ready ‱ Ready with essential tools ‱ PHP Unit, PHP Code Sniffer, PHP Mess Detector ‱ Open source and extensible
  • 4. Who can use? ‱ Senior and Junior PHP developers ‱ Architects who want a fast, secure and performing code structure ‱ Students who want to understand MVC implementation in PHP ‱ Seasoned application developers ‱ Any PHP Programmer
  • 5. Why Monsoon? Monsoon is the framework for you, if ‱ you love core PHP and simple MVC, not a creative vocabulary ‱ you love HTML in view files, not any template engines ‱ you love plain SQL queries in the models, not objects ‱ you love automatic routing in your application, not a rule to define each route ‱ you want to take control of the entire script execution cycle, not some black box ‱ you need a light-weight and secure structure, not an extra-terrestrial folder structure
  • 6. Kick Start Just 2 steps to kick start ‱ Step – 1 : Get the code through Composer ‱ composer create-project monsoon/framework . ‱ Step – 2 : Start the webserver ‱ php –S localhost:8080 -t public/
  • 7. Folder Structure Top level ‱ src ‱ App ‱ Api ‱ Cli ‱ Config ‱ Framework ‱ bin ‱ data ‱ public ‱ resources App/ ‱ Classes ‱ Controllers ‱ Entities ‱ Factories ‱ Helpers ‱ Interfaces ‱ Layouts ‱ Models ‱ Modules/ ‱ Tests ‱ Traits ‱ views Modules/ ‱ Controllers ‱ Models ‱ views Note ‱ Api, App, Cli, Config, Framework folder names have the first letter in uppercase, as they contain classes and need to be PSR-4 compliant ‱ src, views, bin, data, resources, public folders are in lower case Api/ ‱ Services ‱ Tests Config/ ‱ Config.php ‱ .env.php ‱ .routes.php
  • 8. Folder Structure (cont.) data/ ‱ cache ‱ conf ‱ docker ‱ locale ‱ logs ‱ migrations ‱ schema ‱ storage ‱ uploads resources/ ‱ css ‱ fonts ‱ img ‱ js ‱ less public/ ‱ css ‱ files ‱ fonts ‱ img ‱ js
  • 9. Execution Flow ‱ Starts from public/index.php ‱ Calls src/App/Classes/Initialize.php ‱ Loads configuration from ‱ Config/Config.php ‱ Config/.env.php ‱ Config/.routes.php ‱ Automatically invokes your Controller based on the url or route defined ‱ Your Controller invokes your Models/Entities ‱ Renders HTML from your view file ‱ Done !!
  • 10. URL Routing Automatic routing ‱ / ‱ src/App/Controllers/IndexController.php : indexAction() ‱ /forgot-password ‱ src/App/Controllers/ForgotPasswordController.php : indexAction() or ‱ src/App/Modules/ForgotPassword/Controllers/IndexController.php : indexAction() ‱ /account/forgot-password ‱ src/App/Controllers/AccountController.php : forgotPasswordAction() ‱ or ‱ src/App/Modules/Account/ForgotPasswordController.php : indexAction() ‱ /settings/users/edit/23 ‱ src/App/Modules/Settings/Controllers/UsersController.php : editAction(23)
  • 11. URL Routing (cont.) Manual routing ‱ defined in src/App/Config/.routes.php ‱ Example ‱ ”login/(:any)” => “ControllersAccountController@loginAction”
  • 12. Configuration Files ‱ Application configuration ‱ src/Config/Config.php ‱ src/Config/.env.php and src/Config/.routes.php ‱ composer.json – Composer configuration ‱ package.json – NPM package configuration ‱ docker-compose.yml – Docker configuration ‱ Supported by data/docker/Dockerfile ‱ gulpfile.js – For Gulp tasks ‱ phinx.php – Handling database migrations ‱ Migrations will be created in data/migrations/ ‱ phpcs.xml – PHP Coding Standards Ruleset ‱ phpmd.xml – PHP Mess Detector Ruleset ‱ phpunit.xml – PHP Unit configuration file
  • 13. ConfigVariables ‱ Config.php ‱ BASE_URL constant ‱ application ‱ title, url, layout, timezone, uploadMaxFileSize, email, language ‱ env (loaded from .env.php) ‱ name, errorReporting, profiler, ‱ encryptionKey, pepperKey ‱ database (type, hostname, port, database, username, password) ‱ smtp (hostname, port, username, password) ‱ routes (from .routes.php)
  • 14. The “Box” ‱ A class just to hold information ‱ Contains ‱ $data ‱ $identity ‱ $config ‱ $container ‱ .. and variables assigned by you ‱ Accessible across all classes in a static way ‱ Box::$data[‘usersList’] ‱ “Just put it in the box”
  • 15. Controllers src/App/Controllers/UsersController.php <?php namespace Controllers; use FrameworkBox; class UsersController extends FrameworkController { public function indexAction() { // 
 Box::$data[‘username’] = ‘Krishna’; View::renderDefault(‘users/index’); } private function internalMethod() { // 
 } }
  • 16. Models src/App/Models/UsersModel.php <?php namespace Models; class UsersModel extends FrameworkModel { public function getUserDetails($userId) { $sql = ‘SELECT user_name, email_id, designation FROM usersWHERE user_id = ?’; $params = [$userId]; $this->sql($sql, $params); return $this->db->result->rows[0]; } }
  • 17. Views (.phtml) src/App/views/users/index.phtml <?php use FrameworkBox; ?> 
 <div class=“container”> <h5>Welcome <?=Box::$data[‘username’]; ?>!! </h5> <p>You have earned <?=Box::getData(‘userPoints’); ?> in your score card.</p> </div> 

  • 18. Layouts ‱ Layout must have header.phtml and footer.phtml under src/App/Layouts/<layout_name> folder ‱ ”default” layout is used by default ‱ Can be invoked from Controller ‱ View::renderDefault(‘users/index’); ‱ View::render(‘users/index’, ‘custom-layout’); ‱ Box’ed data can be used in the Layout
  • 19. Modules ‱ Modules within your application for HMVC pattern ‱ Sets of Controllers, Models, views ‱ You can also add Interfaces, Helpers, Classes, etc. ‱ PSR-4 compliant ‱ Separate namespace ‱ e.g. namespace ModulesSettingsControllers;
  • 20. Entities src/App/Entities/User.php <?php namespace Entities; class User extends FrameworkEntity { public function __construct() { parent::__construct(); $this->setTableName(‘users’); $this->setIdField(‘user_id’); } } Usage $user = new EntitiesUser(); $user->first_name = ‘Krishna’; $user->last_name = ‘Manda’; $user->email_id = ‘[email protected]’; $user->save(); // 
 echo ‘User Id : ‘.$user->user_id;
  • 21. Framework/ ‱ Application ‱ BootstrapUI ‱ Box ‱ Captcha ‱ Cipher ‱ Config ‱ Container ‱ Controller ‱ Curl ‱ Database ‱ Datagrid ‱ Datasource ‱ Entity ‱ Error ‱ Html ‱ Identity ‱ Locale ‱ Logger ‱ Model ‱ Profiler ‱ Request ‱ Response ‱ Router ‱ Security ‱ Service ‱ Session ‱ Utilities ‱ Validator ‱ View ‱ Watchlist
  • 22. FrameworkSecurity ‱ Security::forceHttps() ‱ Security::setSecureHeaders() ‱ Security::generateSalt(), Security::generateGUID() ‱ Security::generateCSRFToken(), Security::isCSRFTokenValid() ‱ Security::escapeSql() ‱ Security::escapeXSS() ‱ Security::stripTagsContent() ‱ Security::generatePassword() ‱ 
 and more
  • 23. APIs ‱ File name suffixed with ”Service.php” ‱ Similar to App/Controllers have “Controller.php” suffix ‱ Methods in Service are suffixed with “Action” word ‱ App/Controllers also use “Action” ‱ Methods in Service are prefixed with HTTP method ‱ public function getUserOperation($id) ‱ public function postUserOperation($userData) ‱ public function patchUserOperation($changedUserData)
  • 24. API Example src/Api/Services/UsersService.php <?php namespace ApiServices; use ModelsUsersModel; class UsersService extends FrameworkService { public function getUserOperation($userId) { $userData = (new UsersModel)->getUserDetails($userId); $response = new FrameworkResponse(); $response->setHttpStatusCode('200', 'OK’); $response->setData($userData); $response->dispatchJson(); } }
  • 25. CLI Programming ‱ Use the popular Symfony’s Console component (https://symfony.com/doc/current/components/console.html) ‱ Triggering scripts from bin/ ‱ Classes in Cli/ ‱ Flow ‱ Create class in Cli/ and include them in bin/console ‱ Running from terminal, an example ‱ $ php bin/console greet Krishna
  • 26. Dependency Injection (Factory Pattern) src/App/Factories/IndexControllerFactory.php <?php namespace Factories; use ConfigConfig, use ControllersIndexController; use FrameworkContainer; use FrameworkInterfacesFactoryInterface; class IndexControllerFactory implements FactoryInterface { public static function create(Container $container) { return new IndexController($container->get(Config::class)); } } src/App/Controllers/IndexController.php <?php namespace Controllers; class IndexController extends FrameworkController { public function __construct(Config $config) { $this->config = $config; } public function indexAction() { // ... } }
  • 27. Database Migrations ‱ Phinx based migrations (http://docs.phinx.org/en/latest/) ‱ phinx.php – Configuration file ‱ Migration commands ‱ vendor/bin/phinx create MyNewMigration ‱ vendor/bin/phinx migrate ‱ Migrations are created under data/migrations
  • 28. WritingTest Cases ‱ Support for PHPUnit (https://phpunit.readthedocs.io/en/8.2/) ‱ Test cases maintained under ‱ src/App/Tests ‱ src/App/Modules/<module_name>/Tests ‱ src/Api/Tests ‱ Commands ‱ vendor/bin/phpunit
  • 29. Thank you! ‱ Try MonsoonPHP with a small POC ‱ Visit Monsoon PHP website for more video tutorials ‱ https://monsoonphp.com