Example #1
0
 public function initialize()
 {
     if (true === $this->isInitialized) {
         return;
     }
     $data = $this->getRepository()->getClient()->run($this->getRepository(), 'ls-tree -lz ' . $this->getHash());
     $lines = explode("", $data);
     $files = $root = [];
     foreach ($lines as $key => $line) {
         if (empty($line)) {
             unset($lines[$key]);
             continue;
         }
         $files[] = preg_split("/[\\s]+/", $line, 5);
     }
     foreach ($files as $file) {
         if ($file[1] == 'commit') {
             // submodule
             continue;
         }
         if ($file[0] == '120000') {
             $show = $this->getRepository()->getClient()->run($this->getRepository(), 'show ' . $file[2]);
             $tree = new Symlink();
             $tree->setMode($file[0]);
             $tree->setName($file[4]);
             $tree->setPath($show);
             $root[] = $tree;
             continue;
         }
         if ($file[1] == 'blob') {
             $blob = new Blob($file[2], $this->getRepository());
             $blob->setMode($file[0]);
             $blob->setName($file[4]);
             $blob->setSize($file[3]);
             $root[] = $blob;
             continue;
         }
         $tree = new self($file[2], $this->getRepository());
         $tree->setMode($file[0]);
         $tree->setName($file[4]);
         $root[] = $tree;
     }
     $this->data = $root;
     $this->isInitialized = true;
 }
Example #2
0
 /**
  * Creates a new Credentials object with the AuthMode::PUBLIC_KEY authorizationmdoe. Requires username and keys details.
  * @param string $username Authorization username
  * @param string $publicKey Public key path
  * @param string $privateKey Private key path
  * @param string $passphrase Passphrase for Private key (if required)
  * @return Credentials
  */
 public static function withPublicKey($username, $publicKey, $privateKey, $passphrase = null)
 {
     $instance = new self();
     $instance->setMode(AuthMode::PUBLIC_KEY);
     $instance->setUsername($username);
     $instance->setPublicKey($publicKey);
     $instance->setPrivateKey($privateKey, $passphrase);
     return $instance;
 }