1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link https://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Transformer\Writer; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Descriptor\ApiSetDescriptor; |
17
|
|
|
use phpDocumentor\Descriptor\FileDescriptor; |
18
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
19
|
|
|
use phpDocumentor\Transformer\Transformation; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Sourcecode transformation writer; generates syntax highlighted source files in a destination's subfolder. |
23
|
|
|
*/ |
24
|
|
|
class Sourcecode extends WriterAbstract |
25
|
|
|
{ |
26
|
|
|
use IoTrait; |
27
|
|
|
|
28
|
|
|
/** @var PathGenerator */ |
29
|
|
|
private $pathGenerator; |
30
|
|
|
|
31
|
2 |
|
public function __construct(PathGenerator $pathGenerator) |
32
|
|
|
{ |
33
|
2 |
|
$this->pathGenerator = $pathGenerator; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This method writes every source code entry in the structure file to a highlighted file. |
38
|
|
|
* |
39
|
|
|
* @param ProjectDescriptor $project Document containing the structure. |
40
|
|
|
* @param Transformation $transformation Transformation to execute. |
41
|
|
|
*/ |
42
|
2 |
|
public function transform(ProjectDescriptor $project, Transformation $transformation) : void |
43
|
|
|
{ |
44
|
2 |
|
foreach ($project->getVersions() as $version) { |
45
|
2 |
|
foreach ($version->getDocumentationSets() as $documentationSet) { |
46
|
2 |
|
if ($documentationSet instanceof ApiSetDescriptor && |
47
|
2 |
|
$documentationSet->getSettings()['include-source'] === false |
48
|
|
|
) { |
49
|
1 |
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** @var FileDescriptor $file */ |
53
|
1 |
|
foreach ($project->getFiles() as $file) { |
54
|
1 |
|
$source = $file->getSource(); |
55
|
1 |
|
if ($source === null) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$path = $this->pathGenerator->generate($file, $transformation); |
60
|
1 |
|
$this->persistTo($transformation, $path, $source); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
1 |
|
} |
65
|
|
|
} |
66
|
|
|
|