Skip to content

Commit 9def074

Browse files
author
Christian Blanquera
authored
Merge pull request #8 from CradlePHP/1.0
1.0
2 parents ba34b0f + 53f354c commit 9def074

10 files changed

Lines changed: 545 additions & 100 deletions

File tree

.cradle.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
<?php //-->
2+
/**
3+
* This file is part of a package designed for the CradlePHP Project.
4+
*
5+
* Copyright and license information can be found at LICENSE.txt
6+
* distributed with this package.
7+
*/
8+
29
require_once __DIR__ . '/src/events.php';
10+
11+
// boostrap
12+
$this->preprocess(include __DIR__ . '/src/helpers.php');

src/events/deploy/production.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @param Response $response
1717
*/
1818
return function ($request, $response) {
19-
$cwd = $request->getServer('PWD');
19+
$cwd = getcwd();
2020
$deploy = $this->package('global')->config('deploy');
2121

2222
if (empty($deploy)) {

src/events/install.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
}
9494

9595
//setup the configs
96-
$cwd = $request->getServer('PWD');
96+
$cwd = getcwd();
9797
if(!$request->hasStage('skip-configs')) {
9898
CommandLine::system('Setting up config files...');
9999

@@ -125,6 +125,52 @@
125125
}
126126
}
127127

128+
//create compiled, log, public/upload, config/schema
129+
if(!$request->hasStage('skip-mkdir')) {
130+
if (!is_dir($cwd . '/compiled')) {
131+
CommandLine::system('Making ' . $cwd . '/compiled');
132+
mkdir($cwd . '/compiled', 0777);
133+
}
134+
135+
if (!is_dir($cwd . '/log')) {
136+
CommandLine::system('Making ' . $cwd . '/log');
137+
mkdir($cwd . '/log', 0777);
138+
}
139+
140+
if (!is_dir($cwd . '/public/upload')) {
141+
CommandLine::system('Making ' . $cwd . '/public/upload');
142+
mkdir($cwd . '/public/upload', 0777);
143+
}
144+
145+
if (!is_dir($cwd . '/config/schema')) {
146+
CommandLine::system('Making ' . $cwd . '/config/schema');
147+
mkdir($cwd . '/config/schema', 0777);
148+
}
149+
}
150+
151+
//chmod compiled, log, config, public/upload
152+
if(!$request->hasStage('skip-chmod')) {
153+
if (is_dir($cwd . '/compiled')) {
154+
CommandLine::system('chmoding ' . $cwd . '/compiled');
155+
chmod($cwd . '/compiled', 0777);
156+
}
157+
158+
if (is_dir($cwd . '/log')) {
159+
CommandLine::system('chmoding ' . $cwd . '/log');
160+
chmod($cwd . '/log', 0777);
161+
}
162+
163+
if (is_dir($cwd . '/config')) {
164+
CommandLine::system('chmoding ' . $cwd . '/config');
165+
chmod($cwd . '/config', 0777);
166+
}
167+
168+
if (is_dir($cwd . '/public/upload')) {
169+
CommandLine::system('chmoding ' . $cwd . '/public/upload');
170+
chmod($cwd . '/public/upload', 0777);
171+
}
172+
}
173+
128174
if(!$request->hasStage('skip-sql')) {
129175
//SQL
130176
CommandLine::system('Setting up SQL...');
@@ -189,6 +235,4 @@
189235
CommandLine::info('Recommended actions:');
190236
CommandLine::info(' - bin/cradle sql populate');
191237
CommandLine::info(' - yarn build');
192-
CommandLine::info(' - chmod -R 777 config/admin');
193-
CommandLine::info(' - chmod -R 777 config/i18n');
194238
};

src/events/package/install.php

Lines changed: 127 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* distributed with this package.
88
*/
99

10-
use Cradle\Framework\CommandLine;
1110
use Cradle\Framework\Package;
1211
use Cradle\Event\EventHandler;
1312
use Cradle\Composer\Command;
@@ -25,27 +24,45 @@
2524
// get the package version
2625
$version = $request->getStage(1);
2726

27+
// get developer package
28+
$developer = $this->package('cradlephp/cradle-developer');
29+
2830
// empty package name?
2931
if (!$name) {
30-
CommandLine::error(
32+
$developer->packageLog(
33+
'error',
3134
'Not enough arguments. Usage: `cradle package install vendor/package`'
3235
);
3336
}
3437

38+
// reset log file
39+
$developer->packageLog(null, [], $name);
40+
3541
// valid version?
3642
if ($version && !preg_match('/^[0-9\.]+$/i', $version)) {
37-
CommandLine::error(
38-
'Unable to install package. Version is not valid version format should be 0.0.*.'
43+
$developer->packageLog(
44+
'error',
45+
'Unable to install package. Version is not valid version format should be 0.0.*.',
46+
$name,
47+
'install-error'
3948
);
4049
}
4150

51+
// get package config
52+
$config = $this->package('global')->config('packages', $name);
53+
4254
// does the package installed already?
43-
if ($this->package('global')->config('packages', $name)) {
55+
if ($config && isset($config['version'])) {
4456
// let them update instead
45-
CommandLine::error(sprintf(
46-
'Package is already installed. Run `cradle package update %s` instead',
47-
$name
48-
));
57+
$developer->packageLog(
58+
'error',
59+
sprintf(
60+
'Package is already installed. Run `cradle package update %s` instead',
61+
$name
62+
),
63+
$name,
64+
'install-error'
65+
);
4966
}
5067

5168
// get active packages
@@ -65,19 +82,31 @@
6582

6683
// if it's a pseudo package
6784
if ($type === Package::TYPE_PSEUDO) {
68-
CommandLine::error(sprintf(
69-
'Can\'t install pseudo package %s.',
70-
$name
71-
));
85+
$developer->packageLog(
86+
'error',
87+
sprintf('Can\'t install pseudo package %s.', $name),
88+
$name,
89+
'install-error'
90+
);
7291
}
7392

7493
// if it's a root package
7594
if ($type === Package::TYPE_ROOT) {
76-
CommandLine::info(sprintf('Installing root package %s.', $name));
95+
$developer->packageLog(
96+
'info',
97+
sprintf('Installing root package %s.', $name),
98+
$name,
99+
'install-pending'
100+
);
77101

78102
// directory doesn't exists?
79103
if (!is_dir($package->getPackagePath())) {
80-
CommandLine::error('Package does not exists.');
104+
$developer->packageLog(
105+
'error',
106+
'Package does not exists.',
107+
$name,
108+
'install-error'
109+
);
81110
}
82111

83112
// bootstrap file exists?
@@ -88,23 +117,38 @@
88117
'.cradle.php'
89118
)
90119
)) {
91-
CommandLine::error('Bootstrap file .cradle.php does not exists.');
120+
$developer->packageLog(
121+
'warning',
122+
'Bootstrap file .cradle.php does not exists.',
123+
$name,
124+
'install-warning'
125+
);
92126
}
93127

94128
// just let the package process the given version
95129
$request->setStage('version', $version);
96130
}
97131

98132
// if it's a vendor package
99-
if ($type === Package::TYPE_VENDOR && !is_dir($package->getPackagePath())) {
100-
CommandLine::info(sprintf('Installing vendor package %s.', $name));
133+
if ($type === Package::TYPE_VENDOR) {
134+
$developer->packageLog(
135+
'info',
136+
sprintf('Installing vendor package %s.', $name),
137+
$name,
138+
'install-pending'
139+
);
101140

102141
// we need to check from packagist
103142
$results = (new Packagist())->get($name);
104143

105144
// if results is empty
106145
if (!isset($results['packages'][$name])) {
107-
CommandLine::error('Package does not exists from packagists.org.');
146+
$developer->packageLog(
147+
'error',
148+
'Package does not exists from packagists.org.',
149+
$name,
150+
'install-error'
151+
);
108152
}
109153

110154
// if version is not set
@@ -119,7 +163,12 @@
119163

120164
// if no valid version
121165
if (empty($versions)) {
122-
CommandLine::error('Couldn\'t find a valid version.');
166+
$developer->packageLog(
167+
'error',
168+
'Couldn\'t find a valid version.',
169+
$name,
170+
'install-error'
171+
);
123172
}
124173

125174
//sort versions, and get the latest one
@@ -128,15 +177,25 @@
128177
} else {
129178
// if version does not exists
130179
if (!isset($results['packages'][$name][$version])) {
131-
CommandLine::error('Couldn\'t find the provided version.');
180+
$developer->packageLog(
181+
'error',
182+
'Couldn\'t find the provided version.',
183+
$name,
184+
'install-error'
185+
);
132186
}
133187
}
134188

135189
// let them know we're installing via composer
136-
CommandLine::info(sprintf(
137-
'Installing package version %s via composer.',
138-
$version
139-
));
190+
$developer->packageLog(
191+
'info',
192+
sprintf(
193+
'Installing package version %s via composer.',
194+
$version
195+
),
196+
$name,
197+
'install-pending'
198+
);
140199

141200
//increase memory limit
142201
ini_set('memory_limit', -1);
@@ -145,12 +204,31 @@
145204
$composer = $this->package('global')->path('root') . '/vendor/bin/composer';
146205

147206
// run composer require command
148-
(new Command($composer))->require(sprintf('%s:%s', $name, $version));
149-
207+
(new Command($composer))
208+
// set our custom output handler
209+
->setOutputHandler(function($message, $newline) use ($developer, $name) {
210+
// log composer output
211+
$developer->packageLog('info', $message, $name);
212+
})
213+
// require the package
214+
->require(sprintf('%s:%s', $name, $version));
215+
150216
// let them install the package manually
151-
CommandLine::info('Package has been installed.');
217+
$developer->packageLog('info', 'Package has been installed.', $name);
218+
}
152219

153-
// register the package again
220+
// clone the bootstrap file
221+
$bootstrap = new ReflectionClass($package);
222+
// get the methods
223+
$methods = $bootstrap->getProperty('methods');
224+
// make it accessible
225+
$methods->setAccessible(true);
226+
// get methods
227+
$methods = $methods->getValue($package);
228+
229+
// check if install methods is set
230+
if (!isset($methods['install'])) {
231+
// try to register the package
154232
$package = $this->register($name)->package($name);
155233
}
156234

@@ -174,17 +252,34 @@
174252

175253
// if error
176254
if ($response->isError()) {
177-
CommandLine::error($response->getMessage(), false);
255+
$developer->packageLog(
256+
'error',
257+
$response->getMessage(),
258+
$name,
259+
'install-error'
260+
);
261+
178262
return;
179263
}
180264

181265
// if version
182266
if ($response->hasResults('version')) {
183267
// this means that the package itself updates it's version
184268
$version = $response->getResults('version');
185-
CommandLine::success(sprintf('%s was installed to %s', $name, $version));
269+
$developer->packageLog(
270+
'success',
271+
sprintf('%s was installed to %s', $name, $version),
272+
$name,
273+
'install-success'
274+
);
275+
186276
return;
187277
}
188278

189-
CommandLine::success(sprintf('%s was installed', $name));
279+
$developer->packageLog(
280+
'success',
281+
sprintf('%s was installed', $name),
282+
$name,
283+
'install-success'
284+
);
190285
};

src/events/package/list.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* @param Response $response
1717
*/
1818
return function($request, $response) {
19+
// load developer package
20+
$developer = $this->package('cradlephp/cradle-developer');
21+
22+
$developer->packageLog('info', 'List of available packages...');
23+
1924
//tmp
2025
$next = function($path) {
2126
//if there is no install
@@ -155,6 +160,14 @@
155160
}
156161

157162
foreach ($packages as $package) {
158-
CommandLine::info($package['name'] . '(' . $package['version'] . ') -> ' . $package['available']);
163+
$developer->packageLog(
164+
'success',
165+
'* ' . $package['name'] . '(' . $package['version'] . ') -> ' . $package['available']
166+
);
167+
}
168+
169+
if ($request->hasStage('data')) {
170+
$response
171+
->set('json', 'results', $packages);
159172
}
160173
};

0 commit comments

Comments
 (0)