src/Models/Travel.php
public static function build(array $args) {
        if (is_array($args) && array_key_exists("type", $args)) {
            switch ($args["type"]) {
                case Travel::TYPE_BUS:
                    return new BusTravel($args);
                case Travel::TYPE_FLIGHT:
                    return new Flight($args);
            }
        }
        throw new \InvalidArgumentException("Array must contain a valid 'type' field");
    }
public static function build(array $args) {
        if (is_array($args) && array_key_exists("type", $args)) {
            switch ($args["type"]) {
                case Travel::TYPE_BUS:
                    return new BusTravel($args);
                case Travel::TYPE_FLIGHT:
                    return new Flight($args);
            }
        }
        throw new \InvalidArgumentException("Array must contain a valid 'type' field");
    }
public static function build ( array $ args ) { if ( is_array ( $ args ) && array_key_exists ( "type" , $ args ) ) { switch ( $ args [ "type" ] ) { case Travel :: TYPE_BUS : return new BusTravel ( $ args ) ; case Travel :: TYPE_FLIGHT : return new Flight ( $ args ) ; } } throw new \ InvalidArgumentException ( "Array must contain a valid 'type' field" ) ; }
Given an array, instantiates a travel among the possible
types of travel. The decision of what Model to use is made
by the field 'type'
@param array $args: array containing fields of the Travel
@return Travel BusTravel or Flight object
Given an array instantiates a travel among the possible types of travel . The decision of what Model to use is made by the field type