|
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
|
|
|
public function __construct(ResourceRepository $repo) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->repo = $repo; |
|
47
|
|
|
} |
|
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
|
|
|
public function handle(Args $args, IO $io) |
|
58
|
|
|
{ |
|
59
|
|
|
$path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); |
|
60
|
|
|
|
|
61
|
|
|
$resources = $this->repo->find($path); |
|
62
|
|
|
|
|
63
|
|
|
if (!count($resources)) { |
|
64
|
|
|
$io->errorLine(sprintf('No resources found for path %s', $path)); |
|
65
|
|
|
|
|
66
|
|
|
return 1; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($resources as $resource) { |
|
70
|
|
|
if ($resource instanceof BodyResource) { |
|
|
|
|
|
|
71
|
|
|
$io->writeLine($resource->getBody()); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return 0; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.