/** * Construct a conditional segment. * If $condition is true, use the first segment. * Otherwise, use the second segment if it is defined. * If not defined, then segment does not exist. */ public function __construct( $condition, WCSegment $segment1, WCSegment $segment2 = Null ) { if ( $condition ) { parent::__construct( $segment1 ); $this->exists = True; } elseif ( $segment2 == Null ) { $this->exists = False; } else { parent::__construct( $segment2 ); $this->exists = True; } }
/** * Choose the first alternative in the array that exists, and cancel all * other alternatives. * @param array $segments Array of WCSegment objects. */ public function __construct( array $segments = array() ) { $this->exists = False; $theSegment = Null; foreach ( $segments as $segment ) { if ( $segment->exists() ) { if ( $this->exists ) { $segment->cancel(); } else { $this->exists = True; $theSegment = $segment; } } } parent::__construct( $theSegment ); }