PHP Classes

File: facade.php

Recommend this page to a friend!
  Classes of Nemeth Zoltan  >  Design patterns  >  facade.php  >  Download  
File: facade.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Design patterns
Implements several well known design patterns
Author: By
Last change:
Date: 6 years ago
Size: 1,285 bytes
 

Contents

Class file image Download
<?php
/**
 * Created by PhpStorm.
 * User: nemeth.zoltan
 * Date: 2016. 05. 13.
 * Time: 7:55
 */
include __DIR__ . '/vendor/autoload.php';

// Order create
$order = new \DP\Facade\Model\Order();
$order->addProduct(new \DP\Facade\Model\Product(1, 'Product A', 10));
$order->addProduct(new \DP\Facade\Model\Product(1, 'Product B', 5));
$order->addProduct(new \DP\Facade\Model\Product(1, 'Product C', 3));

// Default
$orderService = new \DP\Facade\Service\OrderManager();
$orderService->setInventoryService(new \DP\Facade\Service\Inventory(array('warehouse', 'marketplace')));
$orderService->setPaymentService(new \DP\Facade\Service\Payment('cash on delivery'));
$orderService->setShippingService(new \DP\Facade\Service\Shipping());
$orderService->addOrder($order);
$status = $orderService->makeOrder($order);
echo
'<h3>Order status</h3>';
echo
$status;
echo
'<h3>Order service</h3>';
echo
$orderService;

//
// Facade pattern
$service = new \DP\Facade\FacadeOrder();
$facadeOrder = $service->addOrder(array(
    new \
DP\Facade\Model\Product(1, 'Product D', 10),
    new \
DP\Facade\Model\Product(1, 'Product E', 5),
    new \
DP\Facade\Model\Product(1, 'Product F', 3)
));
echo
'<h3>Order status</h3>';
echo
$service->checkout($facadeOrder);
echo
'<h3>Order service</h3>';
echo
$service;