|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Cli\Application |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The M2IF - Console Tool implementation. |
|
25
|
|
|
* |
|
26
|
|
|
* This is a example console tool implementation that should give developers an impression |
|
27
|
|
|
* on how the M2IF could be used to implement their own Magento 2 importer. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
class Application extends \Symfony\Component\Console\Application |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Regex to read the actual version number from the .semver file. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
const REGEX = "/^\-\-\-\n:major:\s(0|[1-9]\d*)\n:minor:\s(0|[1-9]\d*)\n:patch:\s(0|[1-9]\d*)\n:special:\s'([a-zA-z0-9]*\.?(?:0|[1-9]\d*)?)'\n:metadata:\s'((?:0|[1-9]\d*)?(?:\.[a-zA-z0-9\.]*)?)'/"; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* The application name. |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $name = 'M2IF - Simple Console Tool'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The constructor to initialize the instance. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct() |
|
56
|
|
|
{ |
|
57
|
|
|
|
|
58
|
|
|
// invoke the parent constructor |
|
59
|
|
|
parent::__construct($this->name, vsprintf('%d.%d.%d-%s', $this->parse(dirname(__DIR__) . DIRECTORY_SEPARATOR . '.semver'))); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Parse and return the version number from the application's .semver file. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $semverFile The path to the semver file |
|
66
|
|
|
* |
|
67
|
|
|
* @return array The array with the version information |
|
68
|
|
|
* @throws \Exception Is thrown, if the .semver file is not available or invalid |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function parse($semverFile) |
|
71
|
|
|
{ |
|
72
|
|
|
|
|
73
|
|
|
// load the content of the semver file |
|
74
|
|
|
$output = file_get_contents($semverFile); |
|
75
|
|
|
|
|
76
|
|
|
// extract the version information |
|
77
|
|
|
if (!preg_match_all(self::REGEX, $output, $matches)) { |
|
78
|
|
|
throw new \Exception($this, 'Bad semver file.'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// prepare and return the version number |
|
82
|
|
|
list(, $major, $minor, $patch, $special, $metadata) = array_map('current', $matches); |
|
83
|
|
|
return compact('major', 'minor', 'patch', 'special', 'metadata'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|