|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\ClassLoader\ClassCollectionLoader; |
|
17
|
|
|
use Symfony\Component\Console\Command\Command; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
@trigger_error( |
|
|
|
|
|
|
22
|
|
|
'The '.__NAMESPACE__.'\CreateClassCacheCommand class is deprecated since version 3.39.0 and will be removed in 4.0.', |
|
23
|
|
|
E_USER_DEPRECATED |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* NEXT_MAJOR: Remove this class. |
|
28
|
|
|
* |
|
29
|
|
|
* @deprecated since version sonata-project/admin-bundle 3.39.0 and will be removed in 4.0. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Thomas Rabaix <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class CreateClassCacheCommand extends Command |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
protected static $defaultName = 'cache:create-cache-class'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $cacheDir; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var bool |
|
47
|
|
|
*/ |
|
48
|
|
|
private $debug; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct(string $cacheDir, bool $debug) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->cacheDir = $cacheDir; |
|
53
|
|
|
$this->debug = $debug; |
|
54
|
|
|
|
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function configure() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->setDescription('Generate the classes.php files'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
64
|
|
|
{ |
|
65
|
|
|
$classmap = $this->cacheDir.'/classes.map'; |
|
66
|
|
|
|
|
67
|
|
|
if (!is_file($classmap)) { |
|
68
|
|
|
throw new \RuntimeException(sprintf('The file %s does not exist', $classmap)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$name = 'classes'; |
|
72
|
|
|
$extension = '.php'; |
|
73
|
|
|
|
|
74
|
|
|
$output->write('<info>Writing cache file ...</info>'); |
|
75
|
|
|
ClassCollectionLoader::load( |
|
76
|
|
|
include($classmap), |
|
77
|
|
|
$this->cacheDir, |
|
78
|
|
|
$name, |
|
79
|
|
|
$this->debug, |
|
80
|
|
|
false, |
|
81
|
|
|
$extension |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$output->writeln(' done!'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.