@@ -9,6 +9,9 @@ |
||
| 9 | 9 | private $handle; |
| 10 | 10 | private $columns; |
| 11 | 11 | |
| 12 | + /** |
|
| 13 | + * @param string $filename |
|
| 14 | + */ |
|
| 12 | 15 | function __construct($filename) { |
| 13 | 16 | $this->filename = $filename; |
| 14 | 17 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | |
| 34 | 34 | private function mapFromColumns($record) { |
| 35 | 35 | $row = []; |
| 36 | - foreach($this->columns as $i => $column) |
|
| 36 | + foreach ($this->columns as $i => $column) |
|
| 37 | 37 | { |
| 38 | 38 | $row[$i] = isset($record[$column]) ? $record[$column] : null; |
| 39 | 39 | } |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | function help($args) { |
| 90 | 90 | echo "SSPak: manage SilverStripe .sspak archives.\n\nUsage:\n"; |
| 91 | - foreach($this->getActions() as $action => $info) { |
|
| 91 | + foreach ($this->getActions() as $action => $info) { |
|
| 92 | 92 | echo "sspak $action"; |
| 93 | - if(!empty($info['unnamedArgs'])) { |
|
| 94 | - foreach($info['unnamedArgs'] as $arg) echo " ($arg)"; |
|
| 93 | + if (!empty($info['unnamedArgs'])) { |
|
| 94 | + foreach ($info['unnamedArgs'] as $arg) echo " ($arg)"; |
|
| 95 | 95 | } |
| 96 | - if(!empty($info['namedFlags'])) { |
|
| 97 | - foreach($info['namedFlags'] as $arg) echo " (--$arg)"; |
|
| 96 | + if (!empty($info['namedFlags'])) { |
|
| 97 | + foreach ($info['namedFlags'] as $arg) echo " (--$arg)"; |
|
| 98 | 98 | } |
| 99 | - if(!empty($info['namedArgs'])) { |
|
| 100 | - foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; |
|
| 99 | + if (!empty($info['namedArgs'])) { |
|
| 100 | + foreach ($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; |
|
| 101 | 101 | } |
| 102 | 102 | echo "\n {$info['description']}\n\n"; |
| 103 | 103 | } |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | $filesystem = new FilesystemEntity(null, $executor); |
| 123 | 123 | |
| 124 | - if($pakParts['db']) { |
|
| 124 | + if ($pakParts['db']) { |
|
| 125 | 125 | $dbPath = escapeshellarg($namedArgs['db']); |
| 126 | 126 | $process = $filesystem->createProcess("cat $dbPath | gzip -c"); |
| 127 | 127 | $sspak->writeFileFromProcess('database.sql.gz', $process); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if($pakParts['assets']) { |
|
| 130 | + if ($pakParts['assets']) { |
|
| 131 | 131 | $assetsParentArg = escapeshellarg(dirname($namedArgs['assets'])); |
| 132 | 132 | $assetsBaseArg = escapeshellarg(basename($namedArgs['assets'])); |
| 133 | 133 | $process = $filesystem->createProcess("cd $assetsParentArg && tar cfh - $assetsBaseArg | gzip -c"); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $sspak = new SSPakFile($file, $executor); |
| 151 | 151 | |
| 152 | 152 | // Validation |
| 153 | - if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 153 | + if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 154 | 154 | |
| 155 | 155 | $phar = $sspak->getPhar(); |
| 156 | 156 | $phar->extractTo($dest); |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | $db = new DatabaseConnector($webroot); |
| 183 | 183 | |
| 184 | - foreach($db->getTables() as $table) { |
|
| 185 | - $filename = $destPath . '/' . $table . '.csv'; |
|
| 186 | - echo $filename . "...\n"; |
|
| 184 | + foreach ($db->getTables() as $table) { |
|
| 185 | + $filename = $destPath.'/'.$table.'.csv'; |
|
| 186 | + echo $filename."...\n"; |
|
| 187 | 187 | touch($filename); |
| 188 | 188 | $writer = new CsvTableWriter($filename); |
| 189 | 189 | $db->saveTable($table, $writer); |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | $db = new DatabaseConnector($webroot); |
| 206 | 206 | |
| 207 | - foreach($db->getTables() as $table) { |
|
| 208 | - $filename = $srcPath . '/' . $table . '.csv'; |
|
| 209 | - if(file_exists($filename)) { |
|
| 210 | - echo $filename . "...\n"; |
|
| 207 | + foreach ($db->getTables() as $table) { |
|
| 208 | + $filename = $srcPath.'/'.$table.'.csv'; |
|
| 209 | + if (file_exists($filename)) { |
|
| 210 | + echo $filename."...\n"; |
|
| 211 | 211 | $reader = new CsvTableReader($filename); |
| 212 | 212 | $db->loadTable($table, $reader); |
| 213 | 213 | } else { |
@@ -229,16 +229,16 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | $webroot = new Webroot($unnamedArgs[0], $executor); |
| 231 | 231 | $file = $unnamedArgs[1]; |
| 232 | - if(file_exists($file)) throw new Exception( "File '$file' already exists."); |
|
| 232 | + if (file_exists($file)) throw new Exception("File '$file' already exists."); |
|
| 233 | 233 | |
| 234 | 234 | $sspak = new SSPakFile($file, $executor); |
| 235 | 235 | |
| 236 | - if(!empty($namedArgs['identity'])) { |
|
| 236 | + if (!empty($namedArgs['identity'])) { |
|
| 237 | 237 | // SSH private key |
| 238 | 238 | $webroot->setSSHItentityFile($namedArgs['identity']); |
| 239 | 239 | } |
| 240 | - if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); |
|
| 241 | - else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); |
|
| 240 | + if (!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); |
|
| 241 | + else if (!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); |
|
| 242 | 242 | |
| 243 | 243 | // Look up which parts of the sspak are going to be saved |
| 244 | 244 | $pakParts = $args->pakParts(); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $details = $webroot->sniff(); |
| 248 | 248 | |
| 249 | 249 | // Create a build folder for the sspak file |
| 250 | - $buildFolder = "/tmp/sspak-" . rand(100000,999999); |
|
| 250 | + $buildFolder = "/tmp/sspak-".rand(100000, 999999); |
|
| 251 | 251 | $webroot->exec(array('mkdir', $buildFolder)); |
| 252 | 252 | |
| 253 | 253 | $dbFile = "$buildFolder/database.sql.gz"; |
@@ -258,22 +258,22 @@ discard block |
||
| 258 | 258 | $fileList = array(); |
| 259 | 259 | |
| 260 | 260 | // Save DB |
| 261 | - if($pakParts['db']) { |
|
| 261 | + if ($pakParts['db']) { |
|
| 262 | 262 | // Check the database type |
| 263 | 263 | $dbFunction = 'getdb_'.$details['db_type']; |
| 264 | - if(!method_exists($this,$dbFunction)) { |
|
| 265 | - throw new Exception("Can't process database type '" . $details['db_type'] . "'"); |
|
| 264 | + if (!method_exists($this, $dbFunction)) { |
|
| 265 | + throw new Exception("Can't process database type '".$details['db_type']."'"); |
|
| 266 | 266 | } |
| 267 | 267 | $this->$dbFunction($webroot, $details, $sspak, basename($dbFile)); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Save Assets |
| 271 | - if($pakParts['assets']) { |
|
| 271 | + if ($pakParts['assets']) { |
|
| 272 | 272 | $this->getassets($webroot, $details['assets_path'], $sspak, basename($assetsFile)); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Save git-remote |
| 276 | - if($pakParts['git-remote']) { |
|
| 276 | + if ($pakParts['git-remote']) { |
|
| 277 | 277 | $this->getgitremote($webroot, $sspak, basename($gitRemoteFile)); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $hostArg = ''; |
| 294 | 294 | $portArg = ''; |
| 295 | 295 | if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { |
| 296 | - if (strpos($conf['db_server'], ':')!==false) { |
|
| 296 | + if (strpos($conf['db_server'], ':') !== false) { |
|
| 297 | 297 | // Handle "server:port" format. |
| 298 | 298 | $server = explode(':', $conf['db_server'], 2); |
| 299 | 299 | $hostArg = escapeshellarg("--host=".$server[0]); |
@@ -332,16 +332,16 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | function getgitremote($webroot, $sspak, $gitRemoteFile) { |
| 334 | 334 | // Only do anything if we're copying from a git checkout |
| 335 | - $gitRepo = $webroot->getPath() .'/.git'; |
|
| 336 | - if($webroot->exists($gitRepo)) { |
|
| 335 | + $gitRepo = $webroot->getPath().'/.git'; |
|
| 336 | + if ($webroot->exists($gitRepo)) { |
|
| 337 | 337 | // Identify current branch |
| 338 | 338 | $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'branch')); |
| 339 | - if(preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1])===false) { |
|
| 339 | + if (preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1]) === false) { |
|
| 340 | 340 | // If there is a current branch, use that branch's remove |
| 341 | 341 | $currentBranch = trim($matches[1]); |
| 342 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote")); |
|
| 342 | + $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "branch.$currentBranch.remote")); |
|
| 343 | 343 | $remoteName = trim($output['output']); |
| 344 | - if(!$remoteName) $remoteName = 'origin'; |
|
| 344 | + if (!$remoteName) $remoteName = 'origin'; |
|
| 345 | 345 | |
| 346 | 346 | // Default to origin |
| 347 | 347 | } else { |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // Determine the URL of that remote |
| 353 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"remote.$remoteName.url")); |
|
| 353 | + $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "remote.$remoteName.url")); |
|
| 354 | 354 | $remoteURL = trim($output['output']); |
| 355 | 355 | |
| 356 | 356 | // Determine the current SHA |
| 357 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log','-1','--format=%H')); |
|
| 357 | + $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log', '-1', '--format=%H')); |
|
| 358 | 358 | $sha = trim($output['output']); |
| 359 | 359 | |
| 360 | 360 | $content = "remote = $remoteURL\nbranch = $currentBranch\nsha = $sha\n"; |
@@ -382,22 +382,22 @@ discard block |
||
| 382 | 382 | $pakParts = $args->pakParts(); |
| 383 | 383 | |
| 384 | 384 | $namedArgs = $args->getNamedArgs(); |
| 385 | - if(!empty($namedArgs['identity'])) { |
|
| 385 | + if (!empty($namedArgs['identity'])) { |
|
| 386 | 386 | // SSH private key |
| 387 | 387 | $webroot->setSSHItentityFile($namedArgs['identity']); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Validation |
| 391 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); |
|
| 391 | + if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 392 | 392 | |
| 393 | 393 | // Push database, if necessary |
| 394 | 394 | $namedArgs = $args->getNamedArgs(); |
| 395 | - if($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 395 | + if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 396 | 396 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // Push assets, if neccessary |
| 400 | - if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 400 | + if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 401 | 401 | $webroot->putassets($sspak); |
| 402 | 402 | } |
| 403 | 403 | } |
@@ -419,13 +419,13 @@ discard block |
||
| 419 | 419 | $pakParts = $args->pakParts(); |
| 420 | 420 | |
| 421 | 421 | // Validation |
| 422 | - if($webroot->exists($webroot->getPath())) throw new Exception( "Webroot '$webrootDir' already exists."); |
|
| 423 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); |
|
| 422 | + if ($webroot->exists($webroot->getPath())) throw new Exception("Webroot '$webrootDir' already exists."); |
|
| 423 | + if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 424 | 424 | |
| 425 | 425 | // Create new dir |
| 426 | 426 | $webroot->exec(array('mkdir', $webroot->getPath())); |
| 427 | 427 | |
| 428 | - if($sspak->contains('git-remote')) { |
|
| 428 | + if ($sspak->contains('git-remote')) { |
|
| 429 | 429 | $details = $sspak->gitRemoteDetails(); |
| 430 | 430 | $webroot->putgit($details); |
| 431 | 431 | } |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | // Push database, if necessary |
| 436 | 436 | $namedArgs = $args->getNamedArgs(); |
| 437 | - if($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 437 | + if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 438 | 438 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // Push assets, if neccessary |
| 442 | - if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 442 | + if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 443 | 443 | $webroot->putassets($sspak); |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -466,10 +466,10 @@ discard block |
||
| 466 | 466 | $sspakScript = str_replace('$isSelfExtracting = false;', '$isSelfExtracting = true;', $sspakScript); |
| 467 | 467 | |
| 468 | 468 | // Load the sniffer file |
| 469 | - $snifferFile = dirname(__FILE__) . '/sspak-sniffer.php'; |
|
| 469 | + $snifferFile = dirname(__FILE__).'/sspak-sniffer.php'; |
|
| 470 | 470 | $sspakScript = str_replace("\$snifferFileContent = '';\n", |
| 471 | 471 | "\$snifferFileContent = '" |
| 472 | - . str_replace(array("\\","'"),array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n", $sspakScript); |
|
| 472 | + . str_replace(array("\\", "'"), array("\\\\", "\\'"), file_get_contents($snifferFile))."';\n", $sspakScript); |
|
| 473 | 473 | |
| 474 | 474 | file_put_contents($destFile, $sspakScript); |
| 475 | 475 | chmod($destFile, 0775); |
@@ -26,19 +26,19 @@ discard block |
||
| 26 | 26 | $this->isConnected = true; |
| 27 | 27 | |
| 28 | 28 | // Necessary for SilverStripe's _ss_environment.php loader to work |
| 29 | - $_SERVER['SCRIPT_FILENAME'] = $this->basePath . '/dummy.php'; |
|
| 29 | + $_SERVER['SCRIPT_FILENAME'] = $this->basePath.'/dummy.php'; |
|
| 30 | 30 | |
| 31 | 31 | global $databaseConfig; |
| 32 | 32 | |
| 33 | 33 | // require composers autoloader |
| 34 | - if (file_exists($this->basePath . '/vendor/autoload.php')) { |
|
| 35 | - require_once $this->basePath . '/vendor/autoload.php'; |
|
| 34 | + if (file_exists($this->basePath.'/vendor/autoload.php')) { |
|
| 35 | + require_once $this->basePath.'/vendor/autoload.php'; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (file_exists($this->basePath . '/framework/core/Core.php')) { |
|
| 39 | - require_once($this->basePath . '/framework/core/Core.php'); |
|
| 40 | - } elseif (file_exists($this->basePath . '/sapphire/core/Core.php')) { |
|
| 41 | - require_once($this->basePath . '/sapphire/core/Core.php'); |
|
| 38 | + if (file_exists($this->basePath.'/framework/core/Core.php')) { |
|
| 39 | + require_once($this->basePath.'/framework/core/Core.php'); |
|
| 40 | + } elseif (file_exists($this->basePath.'/sapphire/core/Core.php')) { |
|
| 41 | + require_once($this->basePath.'/sapphire/core/Core.php'); |
|
| 42 | 42 | } else { |
| 43 | 43 | throw new \LogicException("No framework/core/Core.php or sapphire/core/Core.php included in project. Perhaps $this->basePath is not a SilverStripe project?"); |
| 44 | 44 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | function getDatabase() { |
| 57 | 57 | $this->connect(); |
| 58 | 58 | |
| 59 | - if(method_exists('DB', 'get_conn')) { |
|
| 59 | + if (method_exists('DB', 'get_conn')) { |
|
| 60 | 60 | return DB::get_conn(); |
| 61 | 61 | } else { |
| 62 | 62 | return DB::getConn(); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | function getTables() { |
| 70 | 70 | $this->connect(); |
| 71 | 71 | |
| 72 | - if(method_exists('DB', 'table_list')) { |
|
| 72 | + if (method_exists('DB', 'table_list')) { |
|
| 73 | 73 | return DB::table_list(); |
| 74 | 74 | } else { |
| 75 | 75 | return DB::tableList(); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | function getFieldsForTable($tableName) { |
| 83 | 83 | $this->connect(); |
| 84 | 84 | |
| 85 | - if(method_exists('DB', 'field_list')) { |
|
| 85 | + if (method_exists('DB', 'field_list')) { |
|
| 86 | 86 | return DB::field_list($tableName); |
| 87 | 87 | } else { |
| 88 | 88 | return DB::fieldList($tableName); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $fields = $this->getFieldsForTable($tableName); |
| 112 | 112 | |
| 113 | - foreach($reader as $record) { |
|
| 113 | + foreach ($reader as $record) { |
|
| 114 | 114 | foreach ($record as $k => $v) { |
| 115 | 115 | if (!isset($fields[$k])) { |
| 116 | 116 | unset($record[$k]); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $this->columns = null; |
| 25 | 25 | $this->initColumns(); |
| 26 | 26 | |
| 27 | - while(($row = $this->getRow()) !== false) { |
|
| 27 | + while (($row = $this->getRow()) !== false) { |
|
| 28 | 28 | yield $this->mapToColumns($row); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | private function mapToColumns($row) { |
| 35 | 35 | $record = []; |
| 36 | - foreach($row as $i => $value) |
|
| 36 | + foreach ($row as $i => $value) |
|
| 37 | 37 | { |
| 38 | - if(isset($this->columns[$i])) { |
|
| 38 | + if (isset($this->columns[$i])) { |
|
| 39 | 39 | $record[$this->columns[$i]] = $value; |
| 40 | 40 | } else { |
| 41 | - throw new \LogicException("Row contains invalid column #$i\n" . var_export($row, true)); |
|
| 41 | + throw new \LogicException("Row contains invalid column #$i\n".var_export($row, true)); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | return $record; |
@@ -9,6 +9,9 @@ |
||
| 9 | 9 | private $handle; |
| 10 | 10 | private $columns; |
| 11 | 11 | |
| 12 | + /** |
|
| 13 | + * @param string $filename |
|
| 14 | + */ |
|
| 12 | 15 | function __construct($filename) { |
| 13 | 16 | $this->filename = $filename; |
| 14 | 17 | } |
@@ -6,18 +6,18 @@ |
||
| 6 | 6 | { |
| 7 | 7 | function testCsvReading() { |
| 8 | 8 | |
| 9 | - $csv = new CsvTableReader(__DIR__ . '/fixture/input.csv'); |
|
| 9 | + $csv = new CsvTableReader(__DIR__.'/fixture/input.csv'); |
|
| 10 | 10 | $this->assertEquals(['Col1', 'Col2', 'Col3'], $csv->getColumns()); |
| 11 | 11 | |
| 12 | 12 | $extractedData = []; |
| 13 | - foreach($csv as $record) { |
|
| 13 | + foreach ($csv as $record) { |
|
| 14 | 14 | $extractedData[] = $record; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | $this->assertEquals( |
| 18 | 18 | [ |
| 19 | - [ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ], |
|
| 20 | - [ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ] |
|
| 19 | + ['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three'], |
|
| 20 | + ['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"] |
|
| 21 | 21 | ], |
| 22 | 22 | $extractedData |
| 23 | 23 | ); |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | $csv = new CsvTableWriter('/tmp/output.csv'); |
| 14 | 14 | |
| 15 | 15 | $csv->start(['Col1', 'Col2', 'Col3']); |
| 16 | - $csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]); |
|
| 17 | - $csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]); |
|
| 16 | + $csv->writeRecord(['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three']); |
|
| 17 | + $csv->writeRecord(['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]); |
|
| 18 | 18 | $csv->finish(); |
| 19 | 19 | |
| 20 | 20 | $csvContent = file_get_contents('/tmp/output.csv'); |
| 21 | 21 | unlink('/tmp/output.csv'); |
| 22 | 22 | |
| 23 | - $fixture = file_get_contents(__DIR__ . '/fixture/input.csv'); |
|
| 23 | + $fixture = file_get_contents(__DIR__.'/fixture/input.csv'); |
|
| 24 | 24 | |
| 25 | 25 | $this->assertEquals($fixture, $csvContent); |
| 26 | 26 | } |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $csv = new CsvTableWriter('/tmp/output.csv'); |
| 35 | 35 | |
| 36 | - $csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]); |
|
| 37 | - $csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]); |
|
| 36 | + $csv->writeRecord(['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three']); |
|
| 37 | + $csv->writeRecord(['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]); |
|
| 38 | 38 | $csv->finish(); |
| 39 | 39 | |
| 40 | 40 | $csvContent = file_get_contents('/tmp/output.csv'); |
| 41 | 41 | unlink('/tmp/output.csv'); |
| 42 | 42 | |
| 43 | - $fixture = file_get_contents(__DIR__ . '/fixture/input.csv'); |
|
| 43 | + $fixture = file_get_contents(__DIR__.'/fixture/input.csv'); |
|
| 44 | 44 | |
| 45 | 45 | $this->assertEquals($fixture, $csvContent); |
| 46 | 46 | } |
@@ -8,16 +8,16 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | function __construct($path, $executor, $pharAlias = 'sspak.phar') { |
| 10 | 10 | parent::__construct($path, $executor); |
| 11 | - if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); |
|
| 11 | + if (!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); |
|
| 12 | 12 | |
| 13 | 13 | $this->pharAlias = $pharAlias; |
| 14 | 14 | $this->pharPath = $path; |
| 15 | 15 | |
| 16 | 16 | // Executable Phar version |
| 17 | - if(substr($path,-5) === '.phar') { |
|
| 17 | + if (substr($path, -5) === '.phar') { |
|
| 18 | 18 | $this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, |
| 19 | 19 | $this->pharAlias); |
| 20 | - if(!file_exists($this->path)) $this->makeExecutable(); |
|
| 20 | + if (!file_exists($this->path)) $this->makeExecutable(); |
|
| 21 | 21 | |
| 22 | 22 | // Non-executable Tar version |
| 23 | 23 | } else { |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * Add the SSPak executable information into this SSPak file |
| 35 | 35 | */ |
| 36 | 36 | function makeExecutable() { |
| 37 | - if(ini_get('phar.readonly')) { |
|
| 37 | + if (ini_get('phar.readonly')) { |
|
| 38 | 38 | throw new Exception("Please set phar.readonly to false in your php.ini."); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT) . " --no-dev"); |
|
| 41 | + passthru("composer install -d ".escapeshellarg(PACKAGE_ROOT)." --no-dev"); |
|
| 42 | 42 | |
| 43 | 43 | $root = PACKAGE_ROOT; |
| 44 | 44 | $srcRoots = [ |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | 49 | // Add the bin file, but strip of the #! exec header. |
| 50 | - $this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak")); |
|
| 50 | + $this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root."bin/sspak")); |
|
| 51 | 51 | |
| 52 | - foreach($srcRoots as $srcRoot) { |
|
| 53 | - foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root . $srcRoot)) as $fileObj) { |
|
| 54 | - if($fileObj->isFile()) { |
|
| 52 | + foreach ($srcRoots as $srcRoot) { |
|
| 53 | + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root.$srcRoot)) as $fileObj) { |
|
| 54 | + if ($fileObj->isFile()) { |
|
| 55 | 55 | $file = $fileObj->getRealPath(); |
| 56 | 56 | |
| 57 | 57 | $relativeFile = str_replace($root, '', $file); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->phar->setStub($stub); |
| 75 | 75 | chmod($this->path, 0775); |
| 76 | 76 | |
| 77 | - passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT)); |
|
| 77 | + passthru("composer install -d ".escapeshellarg(PACKAGE_ROOT)); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | // Non-executable Phars can't have content streamed into them |
| 104 | 104 | // This means that we need to create a temp file, which is a pain, if that file happens to be a 3GB |
| 105 | 105 | // asset dump. :-/ |
| 106 | - if($this->phar instanceof PharData) { |
|
| 107 | - $tmpFile = '/tmp/sspak-content-' .rand(100000,999999); |
|
| 106 | + if ($this->phar instanceof PharData) { |
|
| 107 | + $tmpFile = '/tmp/sspak-content-'.rand(100000, 999999); |
|
| 108 | 108 | $process->exec(array('outputFile' => $tmpFile)); |
| 109 | 109 | $this->phar->addFile($tmpFile, $filename); |
| 110 | 110 | unlink($tmpFile); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return Stream context |
| 124 | 124 | */ |
| 125 | 125 | function writeStreamForFile($filename) { |
| 126 | - return fopen('phar://' . $this->pharAlias . '/' . $filename, 'w'); |
|
| 126 | + return fopen('phar://'.$this->pharAlias.'/'.$filename, 'w'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | function readStreamForFile($filename) { |
| 135 | 135 | // Note: using pharAlias here doesn't work on Debian Wheezy (nor on Windows for that matter). |
| 136 | 136 | //return fopen('phar://' . $this->pharAlias . '/' . $filename, 'r'); |
| 137 | - return fopen('phar://' . $this->pharPath . '/' . $filename, 'r'); |
|
| 137 | + return fopen('phar://'.$this->pharPath.'/'.$filename, 'r'); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | function gitRemoteDetails() { |
| 154 | 154 | $content = $this->content('git-remote'); |
| 155 | 155 | $details = array(); |
| 156 | - foreach(explode("\n", trim($content)) as $line) { |
|
| 157 | - if(!$line) continue; |
|
| 156 | + foreach (explode("\n", trim($content)) as $line) { |
|
| 157 | + if (!$line) continue; |
|
| 158 | 158 | |
| 159 | - if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { |
|
| 159 | + if (preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { |
|
| 160 | 160 | $details[$matches[1]] = $matches[2]; |
| 161 | 161 | } else { |
| 162 | 162 | throw new Exception("Bad line '$line'"); |
@@ -8,7 +8,9 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | function __construct($path, $executor, $pharAlias = 'sspak.phar') { |
| 10 | 10 | parent::__construct($path, $executor); |
| 11 | - if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); |
|
| 11 | + if(!$this->isLocal()) { |
|
| 12 | + throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); |
|
| 13 | + } |
|
| 12 | 14 | |
| 13 | 15 | $this->pharAlias = $pharAlias; |
| 14 | 16 | $this->pharPath = $path; |
@@ -17,7 +19,9 @@ discard block |
||
| 17 | 19 | if(substr($path,-5) === '.phar') { |
| 18 | 20 | $this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, |
| 19 | 21 | $this->pharAlias); |
| 20 | - if(!file_exists($this->path)) $this->makeExecutable(); |
|
| 22 | + if(!file_exists($this->path)) { |
|
| 23 | + $this->makeExecutable(); |
|
| 24 | + } |
|
| 21 | 25 | |
| 22 | 26 | // Non-executable Tar version |
| 23 | 27 | } else { |
@@ -154,7 +158,9 @@ discard block |
||
| 154 | 158 | $content = $this->content('git-remote'); |
| 155 | 159 | $details = array(); |
| 156 | 160 | foreach(explode("\n", trim($content)) as $line) { |
| 157 | - if(!$line) continue; |
|
| 161 | + if(!$line) { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 158 | 164 | |
| 159 | 165 | if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { |
| 160 | 166 | $details[$matches[1]] = $matches[2]; |