-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathPackageBuild.php
More file actions
82 lines (67 loc) · 1.87 KB
/
Copy pathPackageBuild.php
File metadata and controls
82 lines (67 loc) · 1.87 KB
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
<?php
namespace PHPCensor\Plugin;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
/**
* Create a ZIP or TAR.GZ archive of the entire build.
*
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class PackageBuild extends Plugin
{
protected $filename;
protected $format;
/**
* @return string
*/
public static function pluginName()
{
return 'package_build';
}
/**
* {@inheritDoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->filename = isset($options['filename']) ? $options['filename'] : 'build';
$this->format = isset($options['format']) ? $options['format'] : 'zip';
}
/**
* Executes Composer and runs a specified command (e.g. install / update)
*/
public function execute()
{
$path = $this->builder->buildPath;
if ($this->directory === $path) {
return false;
}
$filename = \preg_replace('/([^a-zA-Z0-9_-]+)/', '', $this->filename);
if (!\is_array($this->format)) {
$this->format = [$this->format];
}
$success = true;
foreach ($this->format as $format) {
switch ($format) {
case 'tar':
$cmd = 'tar cfz "%s/%s.tar.gz" ./*';
break;
default:
case 'zip':
$cmd = 'zip -rq "%s/%s.zip" ./*';
break;
}
$success = $this->builder->executeCommand(
$cmd,
$this->directory,
$this->builder->interpolate($filename, true)
);
}
return $success;
}
}