mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 01:32:22 +01:00
cs Facade
This commit is contained in:
parent
454382d8fb
commit
754ea98fb2
31
Facade/BiosInterface.php
Normal file
31
Facade/BiosInterface.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DesignPatterns\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BiosInterface
|
||||||
|
*/
|
||||||
|
interface BiosInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* execute the BIOS
|
||||||
|
*/
|
||||||
|
public function execute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wait for halt
|
||||||
|
*/
|
||||||
|
public function waitForKeyPress();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* launches the OS
|
||||||
|
*
|
||||||
|
* @param OsInterface $os
|
||||||
|
*/
|
||||||
|
public function launch(OsInterface $os);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* power down BIOS
|
||||||
|
*/
|
||||||
|
public function powerDown();
|
||||||
|
}
|
@ -1,9 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* DesignPatternPHP
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DesignPatterns\Facade;
|
namespace DesignPatterns\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,31 +24,45 @@ namespace DesignPatterns\Facade;
|
|||||||
*/
|
*/
|
||||||
class Facade
|
class Facade
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var OsInterface
|
||||||
|
*/
|
||||||
|
protected $os;
|
||||||
|
|
||||||
protected $opsys;
|
/**
|
||||||
|
* @var BiosInterface
|
||||||
|
*/
|
||||||
protected $bios;
|
protected $bios;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the perfect time to use a dependency injection container
|
* This is the perfect time to use a dependency injection container
|
||||||
* to creaate an instance of this class
|
* to creaate an instance of this class
|
||||||
|
*
|
||||||
|
* @param BiosInterface $bios
|
||||||
|
* @param OsInterface $os
|
||||||
*/
|
*/
|
||||||
public function __construct(BiosInterface $bios, OsInterface $os)
|
public function __construct(BiosInterface $bios, OsInterface $os)
|
||||||
{
|
{
|
||||||
$this->bios = $bios;
|
$this->bios = $bios;
|
||||||
$this->opsys = $os;
|
$this->os = $os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* turn on the system
|
||||||
|
*/
|
||||||
public function turnOn()
|
public function turnOn()
|
||||||
{
|
{
|
||||||
$this->bios->execute();
|
$this->bios->execute();
|
||||||
$this->bios->waitForKeyPress();
|
$this->bios->waitForKeyPress();
|
||||||
$this->bios->launch($this->opsys);
|
$this->bios->launch($this->os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* turn off the system
|
||||||
|
*/
|
||||||
public function turnOff()
|
public function turnOff()
|
||||||
{
|
{
|
||||||
$this->opsys->halt();
|
$this->os->halt();
|
||||||
$this->bios->powerDown();
|
$this->bios->powerDown();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
14
Facade/OsInterface.php
Normal file
14
Facade/OsInterface.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DesignPatterns\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OsInterface
|
||||||
|
*/
|
||||||
|
interface OsInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* halt the OS
|
||||||
|
*/
|
||||||
|
public function halt();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user