LinkORB\Component\Etcd\Client::mkdir PHP Method

mkdir() public method

make a new directory
public mkdir ( string $key, integer $ttl ) : array
$key string
$ttl integer
return array $body
    public function mkdir($key, $ttl = 0)
    {
        $data = array('dir' => 'true');
        if ($ttl) {
            $data['ttl'] = $ttl;
        }
        $request = $this->guzzleclient->put($this->buildKeyUri($key), null, $data, array('query' => array('prevExist' => 'false')));
        $response = $request->send();
        $body = $response->json();
        if (isset($body['errorCode'])) {
            throw new KeyExistsException($body['message'], $body['errorCode']);
        }
        return $body;
    }

Usage Example

Example #1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $server = $input->getArgument('server');
     $key = $input->getArgument('key');
     $ttl = $input->getOption('ttl');
     $output->writeln("<info>making directory `{$key}`</info>");
     $client = new EtcdClient($server);
     $data = $client->mkdir($key, $ttl);
     $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     echo $json;
 }
All Usage Examples Of LinkORB\Component\Etcd\Client::mkdir