Pickle\Package\Util\Dumper::dump PHP Method

dump() public method

public dump ( Pickle\Base\Interfaces\Package $package, $with_version = true ) : array
$package Pickle\Base\Interfaces\Package
return array
    public function dump(Interfaces\Package $package, $with_version = true)
    {
        $data = [];
        $data['name'] = $package->getPrettyName();
        if ($with_version) {
            $data['version'] = $package->getPrettyVersion();
        }
        $data['type'] = $package->getType();
        if ($license = $package->getLicense()) {
            $data['license'] = $license;
        }
        if ($authors = $package->getAuthors()) {
            $data['authors'] = $authors;
        }
        if ($description = $package->getDescription()) {
            $data['description'] = $description;
        }
        if ($support = $package->getSupport()) {
            $data['support'] = $support;
        }
        if ($extra = $package->getExtra()) {
            $data['extra'] = $extra;
        }
        return $data;
    }

Usage Example

Example #1
0
 public function updateJSON()
 {
     if ($this->package->getPrettyVersion() == $this->version) {
         /* Don't touch, it's the same. */
         return;
     }
     $dumper = new Util\Dumper();
     $composer_json = $this->package->getRootDir() . DIRECTORY_SEPARATOR . 'composer.json';
     $this->package->replaceVersion((new VersionParser())->normalize($this->version), $this->version);
     $len = file_put_contents($composer_json, json_encode($dumper->dump($this->package), JSON_PRETTY_PRINT));
     if (!$len) {
         throw new \Exception("Failed to update '{$package_json}'");
     }
 }
Dumper