SlideShare une entreprise Scribd logo
1  sur  29
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

Contenu connexe

Tendances

SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...Sencha
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful ControllersWO Community
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnitWO Community
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6DEEPAK KHETAWAT
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing scienceCharlie Love
 
Enterprise Search Using Apache Solr
Enterprise Search Using Apache SolrEnterprise Search Using Apache Solr
Enterprise Search Using Apache Solrsagar chaturvedi
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newAlexander Makarov
 
Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsMikhail Egorov
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratchtutorialsruby
 
Asset Pipeline
Asset PipelineAsset Pipeline
Asset PipelineEric Berry
 

Tendances (19)

SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
Intro apache
Intro apacheIntro apache
Intro apache
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
 
Building a spa_in_30min
Building a spa_in_30minBuilding a spa_in_30min
Building a spa_in_30min
 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6
 
Andrei shakirin rest_cxf
Andrei shakirin rest_cxfAndrei shakirin rest_cxf
Andrei shakirin rest_cxf
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing science
 
Enterprise Search Using Apache Solr
Enterprise Search Using Apache SolrEnterprise Search Using Apache Solr
Enterprise Search Using Apache Solr
 
SQL injection basics
SQL injection basicsSQL injection basics
SQL injection basics
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
 
Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applications
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratch
 
Asset Pipeline
Asset PipelineAsset Pipeline
Asset Pipeline
 

Similaire à Introduction to Monsoon PHP framework

Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephpeiei lay
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
Leveraging the Chaos tool suite for module development
Leveraging the Chaos tool suite  for module developmentLeveraging the Chaos tool suite  for module development
Leveraging the Chaos tool suite for module developmentzroger
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniterJamshid Hashimi
 
Build A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIBuild A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIStormpath
 
A Beginner's Guide to Ember
A Beginner's Guide to EmberA Beginner's Guide to Ember
A Beginner's Guide to EmberRichard Martin
 
Agiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeAgiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeMario IC
 
CNIT 121: 14 Investigating Applications
CNIT 121: 14 Investigating ApplicationsCNIT 121: 14 Investigating Applications
CNIT 121: 14 Investigating ApplicationsSam Bowne
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Lucidworks
 
Beyond Domino Designer
Beyond Domino DesignerBeyond Domino Designer
Beyond Domino DesignerPaul Withers
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes WorkshopErik Hatcher
 

Similaire à Introduction to Monsoon PHP framework (20)

Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephp
 
Cakeph pppt
Cakeph ppptCakeph pppt
Cakeph pppt
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Leveraging the Chaos tool suite for module development
Leveraging the Chaos tool suite  for module developmentLeveraging the Chaos tool suite  for module development
Leveraging the Chaos tool suite for module development
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniter
 
Apereo OAE - Bootcamp
Apereo OAE - BootcampApereo OAE - Bootcamp
Apereo OAE - Bootcamp
 
Build A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIBuild A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON API
 
A Beginner's Guide to Ember
A Beginner's Guide to EmberA Beginner's Guide to Ember
A Beginner's Guide to Ember
 
Solr Recipes
Solr RecipesSolr Recipes
Solr Recipes
 
Agiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As CodeAgiles Peru 2019 - Infrastructure As Code
Agiles Peru 2019 - Infrastructure As Code
 
CNIT 121: 14 Investigating Applications
CNIT 121: 14 Investigating ApplicationsCNIT 121: 14 Investigating Applications
CNIT 121: 14 Investigating Applications
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
Webscripts Server
Webscripts ServerWebscripts Server
Webscripts Server
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
Beyond Domino Designer
Beyond Domino DesignerBeyond Domino Designer
Beyond Domino Designer
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 

Dernier

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 

Dernier (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 

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 = ‘krishna@example.com’; $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