-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompile
107 lines (90 loc) · 2.42 KB
/
compile
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
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env php
<?php
require_once(__DIR__ . '/src/FactoryGirl/Version.php');
$compiler = new Compiler;
$compiler->run();
// namespace FactoryGirl\Compiler;
class Compiler
{
public $pharFile;
public function run()
{
$version = \FactoryGirl\Version::VERSION;
$this->pharFile = __DIR__ . '/releases/factory_girl_' . $version . '.phar';
if (file_exists($this->pharFile))
unlink($this->pharFile);
$this->compile();
if($this->runTest())
{
echo "compiled!\n";
}
else
{
echo "compile filed\n";
}
}
public function compile()
{
$phar = new \Phar($this->pharFile, 0, 'FactoryGirl');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
// CLI Component files
foreach ($this->getFiles() as $file) {
$path = str_replace(__DIR__.'/', '', $file);
$phar->addFromString($path, file_get_contents($file));
}
// Stubs
$phar['_cli_stub.php'] = $this->getCliStub();
$phar['_web_stub.php'] = $this->getWebStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
$phar->compressFiles(\Phar::GZ);
unset($phar);
}
public function runTest()
{
require($this->pharFile);
FactoryGirl\Factory::defineFactory('Foo', 'Foo', ['name' => 'name_{{sequence}}']);
$foo = FactoryGirl\Factory::create('Foo');
return $foo->name === 'name_0';
}
protected function getCliStub()
{
return "<?php ".$this->getLicense()." require_once __DIR__.'/vendor/autoload.php'; __HALT_COMPILER();";
}
protected function getWebStub()
{
return "<?php throw new \LogicException('This PHAR file can only be used from the CLI.'); __HALT_COMPILER();";
}
protected function getLicense()
{
return '
/**
*
* (c) Kengo Suzuki <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
**/';
}
protected function getFiles()
{
return array(
'LICENSE',
'src/FactoryGirl/Factory.php',
'src/FactoryGirl/Sequence.php',
'src/FactoryGirl/Version.php',
'vendor/autoload.php',
'vendor/composer/autoload_classmap.php',
'vendor/composer/autoload_namespaces.php',
'vendor/composer/autoload_real.php',
'vendor/composer/ClassLoader.php',
'vendor/composer/include_paths.php',
);
}
}
class Foo
{
public $name;
public function save(){ return true; }
}