Hoa central
Paste.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Devtools\Bin;
38 
39 use Hoa\Console;
40 
50 {
56  protected $options = [
57  ['address', Console\GetOption::REQUIRED_ARGUMENT, 'a'],
58  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
59  ['help', Console\GetOption::NO_ARGUMENT, '?']
60  ];
61 
62 
63 
69  public function main()
70  {
71  $address = 'paste.hoa-project.net:80';
72 
73  while (false !== $c = $this->getOption($v)) {
74  switch ($c) {
75  case 'a':
76  $address = $v;
77 
78  break;
79 
80  case 'h':
81  case '?':
82  return $this->usage();
83 
84  case '__ambiguous':
85  $this->resolveOptionAmbiguity($v);
86 
87  break;
88  }
89  }
90 
91  $input = file_get_contents('php://stdin');
92  $context = stream_context_create([
93  'http' => [
94  'method' => 'POST',
95  'header' => 'Host: ' . $address . "\r\n" .
96  'User-Agent: Hoa' . "\r\n" .
97  'Accept: */*' . "\r\n" .
98  'Content-Type: text/plain' . "\r\n" .
99  'Content-Length: ' . strlen($input) . "\r\n",
100  'content' => $input
101  ]
102  ]);
103 
104  echo file_get_contents('http://' . $address, false, $context), "\n";
105 
106  return;
107  }
108 
114  public function usage()
115  {
116  echo
117  'Usage : devtools:paste <options>', "\n",
118  'Options :', "\n",
119  $this->makeUsageOptionsList([
120  'a' => 'Address to the paste server.',
121  'help' => 'This help.'
122  ]), "\n";
123 
124  return;
125  }
126 }
127 
128 __halt_compiler();
129 Paste something somewhere.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190