-
Notifications
You must be signed in to change notification settings - Fork 83
/
ConfigFileStructure.php
95 lines (83 loc) · 2.94 KB
/
ConfigFileStructure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\MagentoCloud\Config\Validator\Build;
use Magento\MagentoCloud\Config\Validator;
use Magento\MagentoCloud\Config\ValidatorInterface;
use Magento\MagentoCloud\Config\Magento\Shared\Resolver;
use Magento\MagentoCloud\Package\UndefinedPackageException;
use Magento\MagentoCloud\Util\ArrayManager;
/**
* Validates that configuration file contains enough data for running static content deploy in build phase.
*
* For magento version 2.1.x scopes configuration should exists in app/etc/config.local.php.
* For version 2.2 and higher in app/etc/config.php.
*/
class ConfigFileStructure implements ValidatorInterface
{
/**
* @var ArrayManager
*/
private $arrayManager;
/**
* @var Validator\ResultFactory
*/
private $resultFactory;
/**
* @var Resolver
*/
private $resolver;
/**
* @param ArrayManager $arrayManager
* @param Validator\ResultFactory $resultFactory
* @param Resolver $resolver
*/
public function __construct(
ArrayManager $arrayManager,
Validator\ResultFactory $resultFactory,
Resolver $resolver
) {
$this->arrayManager = $arrayManager;
$this->resultFactory = $resultFactory;
$this->resolver = $resolver;
}
/**
* {@inheritdoc}
*
* @throws UndefinedPackageException
*/
public function validate(): Validator\ResultInterface
{
$configFile = $this->resolver->getPath();
$config = $this->resolver->read();
$configFileName = basename($configFile);
$flattenedConfig = $this->arrayManager->flatten($config);
$websites = $this->arrayManager->filter($flattenedConfig, 'scopes/websites', false);
$stores = $this->arrayManager->filter($flattenedConfig, 'scopes/stores', false);
if (count($stores) === 0 && count($websites) === 0) {
$error = 'No stores/website/locales found in ' . $configFileName;
$suggestion = implode(
PHP_EOL,
[
'To speed up the deploy process do the following:',
'1. Using SSH, log in to your Magento Cloud account',
'2. Run "php ./vendor/bin/ece-tools config:dump"',
'3. Using SCP, copy the app/etc/%s file to your local repository',
'4. Add, commit, and push your changes to the app/etc/%s file',
]
);
$suggestion = sprintf($suggestion, $configFileName, $configFileName);
return $this->resultFactory->create(
Validator\ResultInterface::ERROR,
[
'error' => $error,
'suggestion' => $suggestion,
]
);
}
return $this->resultFactory->create(Validator\ResultInterface::SUCCESS);
}
}