DrewM\Morse\Morse::getFirstAvailable PHP Method

getFirstAvailable() public static method

Tests an array of feature identifiers, stopping and returnig the first that tests true.
public static getFirstAvailable ( array $featureIDs = [] ) : string
$featureIDs array Array of feature ID strings. If associative, the value is the ID, and the key is returned.
return string Returns the first feature ID that tests true.
    public static function getFirstAvailable(array $featureIDs = array())
    {
        if (is_array($featureIDs) && count($featureIDs)) {
            foreach ($featureIDs as $featureID) {
                if (self::featureExists($featureID)) {
                    $parts = explode('/', $featureID);
                    return $parts[1];
                }
            }
        }
        return null;
    }

Usage Example

Example #1
0
 public function testGetFirstAvailable()
 {
     $this->assertEquals(Morse::getFirstAvailable(array('image/fake-negative', 'image/fake-negative', 'image/fake-positive')), 'fake-positive');
     $this->assertEquals(Morse::getFirstAvailable(array('db/fake-positive', 'db/fake-negative')), 'fake-positive');
     $this->assertSame(Morse::getFirstAvailable(array('text/fake-negative')), null);
 }