Add command to create custom types
[shpub.git] / src / shpub / Command / X.php
1 <?php
2 namespace shpub;
3
4 /**
5  * Create a object with a custom type
6  *
7  * @author  Christian Weiske <cweiske@cweiske.de>
8  * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
9  * @link    http://cweiske.de/shpub.htm
10  */
11 class Command_X extends Command_AbstractProps
12 {
13     public static function opts(\Console_CommandLine $optParser)
14     {
15         $cmd = $optParser->addCommand('x');
16         $cmd->description = 'Create a custom type';
17         static::addOptHtml($cmd);
18         static::optsGeneric($cmd);
19         $cmd->addArgument(
20             'type',
21             [
22                 'optional'    => false,
23                 'multiple'    => false,
24                 'description' => 'Microformat object type',
25             ]
26         );
27     }
28
29     public function run(\Console_CommandLine_Result $cmdRes)
30     {
31         $req = new Request($this->cfg->host, $this->cfg);
32         $req->setType($cmdRes->args['type']);
33         $this->handleGenericOptions($cmdRes, $req);
34
35         $res = $req->send();
36         $postUrl = $res->getHeader('Location');
37         Log::info('Object created at server');
38         Log::msg($postUrl);
39     }
40 }
41 ?>