Ptondereau\PackMe\Package::toArray PHP Method

toArray() public method

Return keywords list.
public toArray ( ) : array
return array
    public function toArray()
    {
        $this->validator->verify($this);
        $this->parseAuthor($this->author);
        $packageInfo = explode('/', $this->name);
        $this->vendor = Str::studly($packageInfo[0]);
        $this->package = Str::studly($packageInfo[1]);
        return ['name' => $this->name, 'description' => $this->description ?: '', 'vendor' => $this->vendor, 'package' => $this->package, 'authorName' => $this->authorName, 'authorEmail' => $this->email, 'config' => Str::slug($this->package)];
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Craft the application with parameters.
  *
  * @param Package $package
  *
  * @return mixed
  */
 public function craft(Package $package)
 {
     $stubPath = realpath(__DIR__ . '/../stubs');
     // set delimiters
     $this->stubber->withDelimiters('{{', '}}');
     // set keywords
     $this->stubber->setRaw($package->toArray());
     $this->filesystem->mirror($stubPath, $package->getDestination());
     // array of all stub files
     $stubFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($package->getDestination(), \RecursiveDirectoryIterator::SKIP_DOTS));
     // find and replace
     foreach ($stubFiles as $stub) {
         $new = pathinfo($stub);
         $this->stubber->useStub($stub);
         if ($this->isConfigFile($new['basename'])) {
             $this->stubber->generate($new['dirname'] . '/' . Str::slug($package->getPackage()) . '.php');
         } elseif ($this->isServiceProviderFile($new['basename'])) {
             $this->stubber->generate($new['dirname'] . '/' . $package->getPackage() . 'ServiceProvider.php');
         } else {
             $this->stubber->generate($new['dirname'] . '/' . $new['filename']);
         }
         $this->filesystem->remove($stub);
     }
 }