PHP code example of phunkie / phunkie-adt

1. Go to this page and download the library: Download phunkie/phunkie-adt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phunkie / phunkie-adt example snippets



interface WeekDay {
    const SUNDAY = 'Sunday',
          MONDAY = 'Monday',
          TUESDAY = 'Tuesday',
          WEDNESDAY = 'Wednesday',
          THURSDAY = 'Thursday',
          FRIDAY = 'Friday',
          SATURDAY = 'Saturday';
}


interface Weekday {}
final class Sunday implements Weekday { }
final class Monday implements Weekday { }
//...


function orderPizza(Weekday $weekday, Pizza $pizza)
{
    switch (get_class($weekday)) {
        case Wednesday::class : return new WednesdayPromotionOrder($pizza);
        default : return new Order($pizza);
    }
}


final class Plutoday implements Weekday { }


abstract class Weekday implements TypeConstructor { use SumType; }


abstract class Weekday extends ImmutableSealed implements TypeConstructor { use SumType; }


abstract class Weekday extends ImmutableSealed implements TypeConstructor, SumTypeTag {
    const sealedTo = [ Sunday::class, Monday::class, Tuesday::class,
        Wednesday::class, Thursday::class, Friday::class, Saturday::class];
    public function __construct() { $this->applySeal(); }
}


final class Sunday extends Weekday { use SumType; const typeConstructor = Weekday::class; }
final class Monday extends Weekday { use SumType; const typeConstructor = Weekday::class; }
//...
final class Saturday extends Weekday { use SumType; const typeConstructor = Weekday::class; }


final class Plotoday extends Weekday { use SumType; const typeConstructor = Weekday::class; }

new Plutoday; // results in:
              // TypeError has been thrown with message: "Weekday is sealed and cannot be extended outside seal."