1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Sprint |
4
|
|
|
* |
5
|
|
|
* A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
* |
25
|
|
|
* @package Sprint |
26
|
|
|
* @author Lonnie Ezell |
27
|
|
|
* @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
28
|
|
|
* @license http://opensource.org/licenses/MIT (MIT) |
29
|
|
|
* @link http://sprintphp.com |
30
|
|
|
* @since Version 1.0 |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* BUILD TOOL |
35
|
|
|
* |
36
|
|
|
* This is a simple tool to create the releases for Sprint. The primary tasks are: |
37
|
|
|
* - Create a zip file of final state of code ready for upload |
38
|
|
|
* - Remove our tests folder |
39
|
|
|
* - Remove any logs and cache items from the app that it might have |
40
|
|
|
* - remove this build folder |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
use Myth\CLI; |
44
|
|
|
|
45
|
|
|
$start_time = microtime(true); |
46
|
|
|
|
47
|
|
|
// Ensure errors are on |
48
|
|
|
error_reporting(-1); |
49
|
|
|
ini_set('display_errors', 1); |
50
|
|
|
|
51
|
|
|
// Load our autoloader |
52
|
|
|
require __DIR__ .'/../vendor/autoload.php'; |
53
|
|
|
|
54
|
|
|
// Load configuration |
55
|
|
|
require 'build_config.php'; |
56
|
|
|
|
57
|
|
|
// Folder definitions |
58
|
|
|
define('BUILDBASE', __DIR__ .'/'); |
59
|
|
|
|
60
|
|
|
// Don't stop script exectuion on 404... |
61
|
|
|
function show_404($page = '', $log_error = TRUE) {} |
62
|
|
|
|
63
|
|
|
// Make sure we have access to CI() object. |
64
|
|
|
ob_start(); |
65
|
|
|
require( BUILDBASE .'../index.php' ); |
66
|
|
|
ob_end_clean(); |
67
|
|
|
|
68
|
|
|
//-------------------------------------------------------------------- |
69
|
|
|
// Determine the build script to run |
70
|
|
|
//-------------------------------------------------------------------- |
71
|
|
|
|
72
|
|
|
$release = CLI::segment(1); |
73
|
|
|
|
74
|
|
|
if (empty($release)) |
75
|
|
|
{ |
76
|
|
|
$release = CLI::prompt("Which script", array_keys($config['builds']) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (! array_key_exists($release, $config['builds'])) |
80
|
|
|
{ |
81
|
|
|
CLI::error('Invalid build specified: '. $release); |
82
|
|
|
exit(1); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
//-------------------------------------------------------------------- |
86
|
|
|
// Instantiate the class and run it |
87
|
|
|
//-------------------------------------------------------------------- |
88
|
|
|
|
89
|
|
|
$class_name = $config['builds'][$release]; |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
if (! file_exists(BUILDBASE ."scripts/{$class_name}.php")) |
93
|
|
|
{ |
94
|
|
|
CLI::error('Unable to find build script: '. $class_name .'.php'); |
95
|
|
|
exit(1); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
require BUILDBASE ."lib/BaseBuilder.php"; |
99
|
|
|
require BUILDBASE ."scripts/{$class_name}.php"; |
100
|
|
|
|
101
|
|
|
$builder = new $class_name( $config['destinations'][$release], get_instance() ); |
102
|
|
|
|
103
|
|
|
if (! is_object($builder)) |
104
|
|
|
{ |
105
|
|
|
CLI::error('Unable to make new class: '. $class_name); |
106
|
|
|
exit(1); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// run it! |
110
|
|
|
CLI::write("Running builder `{$release}` ({$class_name})...", 'yellow'); |
111
|
|
|
|
112
|
|
|
$builder->run(); |
113
|
|
|
|
114
|
|
|
//-------------------------------------------------------------------- |
115
|
|
|
// Show closing comments |
116
|
|
|
//-------------------------------------------------------------------- |
117
|
|
|
|
118
|
|
|
$end_time = microtime(true); |
119
|
|
|
$elapsed_time = number_format($end_time - $start_time, 4); |
120
|
|
|
|
121
|
|
|
CLI::write('Done in '. $elapsed_time .' seconds', 'green'); |
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.