예제 #1
0
 /**
  * @param Client $client
  * @param array $data
  * @return Project
  */
 public static function fromArray(Client $client, array $data)
 {
     $project = new static($data['id']);
     $project->setClient($client);
     if (isset($data['owner'])) {
         $data['owner'] = User::fromArray($client, $data['owner']);
     }
     if (isset($data['namespace']) && is_array($data['namespace'])) {
         $data['namespace'] = ProjectNamespace::fromArray($client, $data['namespace']);
     }
     return $project->hydrate($data);
 }
 /**
  * @return ProjectNamespaces[]
  * @throws \Gitlab\Exception\InvalidArgumentException
  */
 public function getAllProjectNamespaces()
 {
     if (null === $this->allProjectNamespaces) {
         $client = $this->getGitLabClient();
         $allProjectNamespaces = [];
         /** @var ProjectNamespaces $apiProjectNamespaces */
         $apiProjectNamespaces = $client->api('namespaces');
         for ($i = 1; $i < static::MAX_PAGE; $i++) {
             $projectNamespaces = $apiProjectNamespaces->all($i, self::PER_PAGE);
             if (0 === count($projectNamespaces)) {
                 break;
             }
             foreach ($projectNamespaces as $projectNamespace) {
                 $projectNamespace = ProjectNamespace::fromArray($client, $projectNamespace);
                 $allProjectNamespaces[$projectNamespace->id] = $projectNamespace;
             }
         }
         $this->allProjectNamespaces = $allProjectNamespaces;
     }
     return $this->allProjectNamespaces;
 }