Ejemplo n.º 1
0
 private function _refreshPackage(Package $package)
 {
     // Get latest info
     try {
         $packgist = new Packagist();
         $data = $packgist->package($package->author, $package->name);
     } catch (\Exception $e) {
         return null;
     }
     //print_r($data);exit;
     // Save package data
     $package->description = $data['description'];
     $package->downloads = $data['downloads']['total'];
     $package->downloads_m = $data['downloads']['monthly'];
     $package->downloads_d = $data['downloads']['daily'];
     $package->stars = $data['favers'];
     $package->type = $data['type'];
     $package->repo = $data['repository'];
     $package->domain = parse_url($data['repository'], PHP_URL_HOST);
     $package->save();
     // Maintainers
     $ids = [];
     foreach ($data['maintainers'] as $maintainer) {
         $model = Maintainer::firstOrCreate(['name' => $maintainer['name']]);
         $ids[] = $model->id;
     }
     $package->maintainers()->sync($ids);
     // Get the latets version
     usort($data['versions'], function ($a, $b) {
         $a = $a['time'];
         $b = $b['time'];
         if ($a == $b) {
             return 0;
         }
         return $a > $b ? -1 : 1;
     });
     if (isset($data['versions'][0])) {
         $data = $data['versions'][0];
         // Authors
         $ids = [];
         if (isset($data['authors'])) {
             foreach ($data['authors'] as $author) {
                 if (isset($author['email']) && $author['email']) {
                     $model = Author::firstOrNew(['email' => $author['email']]);
                     foreach ($author as $field => $value) {
                         if ($value) {
                             $value = Transliterator::unaccent($value);
                             $model->{$field} = $value;
                         }
                     }
                     $model->save();
                     $ids[] = $model->id;
                 }
             }
         }
         $package->authors()->sync($ids);
         // Tags
         $ids = [];
         if (isset($data['keywords'])) {
             foreach ($data['keywords'] as $tag) {
                 $model = Tag::firstOrCreate(['name' => $tag]);
                 $ids[] = $model->id;
             }
         }
         $package->tags()->sync($ids);
         // Dependencies
         $ids = [];
         if (isset($data['require'])) {
             foreach ($data['require'] as $fullNname => $version) {
                 $explode = explode('/', $fullNname, 2);
                 list($author, $name) = array_pad($explode, 2, '');
                 $model = Package::where('author', '=', $author)->where('name', '=', $name)->get()->first();
                 if ($model) {
                     $ids[$model->id] = ['version' => $version];
                 }
             }
         }
         $package->dependencies()->sync($ids);
     }
     // Mark as updated even if nothing changed.
     $package->touch();
     return $package;
 }
Ejemplo n.º 2
0
 /**
  * @group medium
  *
  * @throws Exception
  */
 public function testPackageException()
 {
     $this->setExpectedException('Exception');
     $packagist = new Packagist('http://packagist.org');
     $package = $packagist->package('xxx');
 }