SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 

Kürzlich hochgeladen (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 

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