|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPixie\CLI; |
| 4 | + |
| 5 | +class Builder |
| 6 | +{ |
| 7 | + /** |
| 8 | + * |
| 9 | + * @var \PHPixie\CLI\Context\Container\Implementation |
| 10 | + */ |
| 11 | + protected $contextContainer; |
| 12 | + |
| 13 | + public function __construct($contextContainer = null) |
| 14 | + { |
| 15 | + $this->contextContainer = $contextContainer; |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * |
| 20 | + * @param string $resource |
| 21 | + * @return \PHPixie\CLI\Stream\Input |
| 22 | + */ |
| 23 | + public function inputStream($resource) |
| 24 | + { |
| 25 | + return new Stream\Input($resource); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * |
| 30 | + * @param string $resource |
| 31 | + * @return \PHPixie\CLI\Stream\Output |
| 32 | + */ |
| 33 | + public function outputStream($resource) |
| 34 | + { |
| 35 | + return new Stream\Output($resource); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * |
| 40 | + * @return \PHPixie\CLI\Context\SAPI |
| 41 | + */ |
| 42 | + public function context() |
| 43 | + { |
| 44 | + return $this->contextContainer()->cliContext(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * |
| 49 | + * @return \PHPixie\CLI\Context\Container\Implementation |
| 50 | + */ |
| 51 | + public function contextContainer() |
| 52 | + { |
| 53 | + if($this->contextContainer === null) { |
| 54 | + $context = $this->buildSapiContext(); |
| 55 | + $this->contextContainer = $this->buildContextContainer($context); |
| 56 | + } |
| 57 | + |
| 58 | + return $this->contextContainer; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * |
| 63 | + * @param \PHPixie\CLI\Context\SAPI $context |
| 64 | + * @return \PHPixie\CLI\Context\Container\Implementation |
| 65 | + */ |
| 66 | + public function buildContextContainer($context) |
| 67 | + { |
| 68 | + return new \PHPixie\CLI\Context\Container\Implementation($context); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * |
| 73 | + * @return \PHPixie\CLI\Context\SAPI |
| 74 | + */ |
| 75 | + public function buildSapiContext() |
| 76 | + { |
| 77 | + return new Context\SAPI($this); |
| 78 | + } |
| 79 | +} |
0 commit comments