Studio\Package::fromFolder PHP Method

fromFolder() public static method

public static fromFolder ( $path )
    public static function fromFolder($path)
    {
        $composerFile = "{$path}/composer.json";
        if (!file_exists($composerFile)) {
            throw new InvalidArgumentException("Unable to detect Composer package in {$path}.");
        }
        $composer = json_decode(file_get_contents($composerFile));
        if (!$composer->name) {
            throw new InvalidArgumentException("Unable to load package name from {$path}/composer.json.");
        }
        list($vendor, $name) = explode('/', $composer->name, 2);
        return new static($vendor, $name, $path);
    }

Usage Example

 public function serializePaths(array $paths)
 {
     $globbedPaths = array_map(function ($path) {
         return glob($path, GLOB_MARK | GLOB_ONLYDIR);
     }, $paths);
     $allPaths = array_reduce($globbedPaths, function ($collect, $pathOrPaths) {
         if (is_array($pathOrPaths)) {
             return array_merge($collect, $pathOrPaths);
         } else {
             $collect[] = $pathOrPaths;
             return $collect;
         }
     }, []);
     $allPaths = array_filter($allPaths, function ($path) {
         return is_dir($path) && file_exists("{$path}/composer.json");
     });
     $packages = array_map(function ($path) {
         return Package::fromFolder(rtrim($path, '/'));
     }, $allPaths);
     $packagePaths = array_reduce($packages, function ($collect, Package $package) {
         $collect[$package->getComposerId()] = $package->getPath();
         return $collect;
     }, []);
     return ['packages' => $packagePaths];
 }
All Usage Examples Of Studio\Package::fromFolder