What is the framework?

A PHP framework is a collection of pre-written code that helps developers to build web application more efficiently. It provides tools and libraries for command tasks like routing,database, interactions and security. PHP frameworks generally follow certain design patterns like MVC (Model-View-Controller).

What is MVVM?

MVVM stands for Model-View-ViewModel.

Model: The Model represents the data and business logic of the application.

View:The View is the user interface of the application. It is responsible for displaying the data that the Model provides.

Controller: The Controller acts as an intermediary between the Model and the View.

ViewModel: The ViewModel serves as the middle-man between the Model and the View.

What design pattern ?

  • 1.Factory pattern: : a method that creates and returns objects without exposing the instantiation logic
    • class Automobile { private $bikeMake; public function __construct($make, $model) { $this->bikeMake = $make; } public function getMakeAndModel() { return $this->bikeMake; } } class AutomobileFactory { public static function create($make, $model) { return new Automobile($make, $model); } } $pulsar = AutomobileFactory::create('ktm', 'Pulsar'); print_r($pulsar->getMakeAndModel()); 2. Singleton: make sure that a class has one
  • 2. Singleton: make sure that a class has one instance of a class that is produced like database connection and mailer class
    • class Singleton { private static $instance; private function __construct() {} private function __clone() {} public static function getInstance() { if (self::$instance === null) { self::$instance = new Singleton(); } return self::$instance; } } $singleton = Singleton::getInstance();
  • 3.Repository Pattern:It is a collection of domain objects, acting like an in-memory collection. The repository is responsible for providing access to data.
  • 4.Observer Pattern: Allows a subject to notify a list of observers when its state changes.
    • class Subject {

      private $observers = [];

      public function addObserver(Observer $observer) {

      $this->observers[] = $observer;

      }

      public function notifyObservers($state) {

      foreach ($this->observers as $observer) {

      $observer->update($state);

      } } }

      $subject = new Subject(); $observer1 = new ConcreteObserver();

      $observer2 = new ConcreteObserver();

      $subject->addObserver($observer1);

      $subject->addObserver($observer2);

      $subject->notifyObservers("New state");