1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Cli\Handler; |
13
|
|
|
|
14
|
|
|
use Puli\Repository\Api\Resource\BodyResource; |
15
|
|
|
use Puli\Repository\Api\ResourceRepository; |
16
|
|
|
use Webmozart\Console\Api\Args\Args; |
17
|
|
|
use Webmozart\Console\Api\IO\IO; |
18
|
|
|
use Webmozart\PathUtil\Path; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Handles the "cat" command. |
22
|
|
|
* |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @author Stephan Wentz <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class CatCommandHandler |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var ResourceRepository |
31
|
|
|
*/ |
32
|
|
|
private $repo; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $currentPath = '/'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Creates the handler. |
41
|
|
|
* |
42
|
|
|
* @param ResourceRepository $repo The resource repository. |
43
|
|
|
*/ |
44
|
3 |
|
public function __construct(ResourceRepository $repo) |
45
|
|
|
{ |
46
|
3 |
|
$this->repo = $repo; |
47
|
3 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Handles the "ls" command. |
51
|
|
|
* |
52
|
|
|
* @param Args $args The console arguments. |
53
|
|
|
* @param IO $io The I/O. |
54
|
|
|
* |
55
|
|
|
* @return int The status code. |
56
|
|
|
*/ |
57
|
3 |
|
public function handle(Args $args, IO $io) |
58
|
|
|
{ |
59
|
3 |
|
$path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); |
60
|
|
|
|
61
|
3 |
|
$resources = $this->repo->find($path); |
62
|
|
|
|
63
|
3 |
|
if (!count($resources)) { |
64
|
|
|
$io->errorLine(sprintf('No resources found for path %s', $path)); |
65
|
|
|
|
66
|
|
|
return 1; |
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
foreach ($resources as $resource) { |
70
|
3 |
|
if ($resource instanceof BodyResource) { |
71
|
3 |
|
$io->writeLine($resource->getBody()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
3 |
|
return 0; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|