Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Last active July 9, 2020 05:09
Show Gist options
  • Save DarkGhostHunter/1aba442f489bbfb243ab6d765cf2202e to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/1aba442f489bbfb243ab6d765cf2202e to your computer and use it in GitHub Desktop.
Container example
<?php
class ExampleController
{
/**
* The new way
*
* @param Transport $transport
* @param Package $package
* @param Weather $weather
* @return PendingDelivery
*/
public function theNewWay(Transport $transport, Package $package, Weather $weather)
{
return $transport->when($package->isBig())->useVan()
->when($package->isFragile())->handleWithCaution()
->when($weather->isDangerous())->notifyPossibleDelay()
->deliver();
}
/**
* The old way
*
* @param Transport $transport
* @param Package $package
* @param Weather $weather
* @return PendingDelivery
*/
public function theOldWay(Transport $transport, Package $package, Weather $weather)
{
if ($package->isBig()) {
$transport->useVan();
}
if ($package->isFragile()) {
$transport->handleWithCaution();
}
if ($weather->isDangerous()) {
$transport->notifyPossibleDelay();
}
return $transport->deliver();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment