Platformsh\Cli\Local\LocalApplication::getToolstack PHP Method

getToolstack() public method

Get the toolstack for the application.
public getToolstack ( ) : Platformsh\Cli\Local\Toolstack\ToolstackInterface | false
return Platformsh\Cli\Local\Toolstack\ToolstackInterface | false
    public function getToolstack()
    {
        $toolstackChoice = false;
        // For now, we reconstruct a toolstack string based on the 'type' and
        // 'build.flavor' config keys.
        $appConfig = $this->getConfig();
        if (isset($appConfig['type'])) {
            list($stack, ) = explode(':', $appConfig['type'], 2);
            $flavor = isset($appConfig['build']['flavor']) ? $appConfig['build']['flavor'] : 'default';
            // Toolstack classes for HHVM are the same as PHP.
            if ($stack === 'hhvm') {
                $stack = 'php';
            }
            $toolstackChoice = "{$stack}:{$flavor}";
            // Alias php:default to php:composer.
            if ($toolstackChoice === 'php:default') {
                $toolstackChoice = 'php:composer';
            }
            if ($flavor === 'none') {
                $toolstackChoice = 'none';
            }
        }
        foreach (self::getToolstacks() as $toolstack) {
            $key = $toolstack->getKey();
            if (!$toolstackChoice && $toolstack->detect($this->getRoot()) || $key && $toolstackChoice === $key) {
                return $toolstack;
            }
        }
        if ($toolstackChoice) {
            throw new \Exception("Toolstack not found: {$toolstackChoice}");
        }
        return false;
    }

Usage Example

 public function testToolstackDetectionNone()
 {
     $toolstackClassName = self::TOOLSTACK_NAMESPACE . 'NoToolstack';
     $fakeAppRoot = 'tests/data/apps';
     $app = new LocalApplication($fakeAppRoot);
     $this->assertInstanceOf($toolstackClassName, $app->getToolstack(), 'File structure does not indicate a specific toolstack');
 }
All Usage Examples Of Platformsh\Cli\Local\LocalApplication::getToolstack