From 524c66dc90847e6411ef228f46e2bfd7c6816303 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Tue, 10 Jan 2017 17:05:43 +0000 Subject: [PATCH 01/10] added files --- public/count.html.php | 12 ++++++++++++ public/count.php | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 public/count.html.php create mode 100644 public/count.php diff --git a/public/count.html.php b/public/count.html.php new file mode 100644 index 0000000..ab4ce83 --- /dev/null +++ b/public/count.html.php @@ -0,0 +1,12 @@ + + + + + Counting to Ten + + +

+ +

+ + \ No newline at end of file diff --git a/public/count.php b/public/count.php new file mode 100644 index 0000000..84594b5 --- /dev/null +++ b/public/count.php @@ -0,0 +1,7 @@ + Date: Tue, 10 Jan 2017 17:56:41 +0000 Subject: [PATCH 02/10] moved count.html.php to project directory --- public/count.html.php => count.html.php | 0 public/count.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename public/count.html.php => count.html.php (100%) diff --git a/public/count.html.php b/count.html.php similarity index 100% rename from public/count.html.php rename to count.html.php diff --git a/public/count.php b/public/count.php index 84594b5..bf18560 100644 --- a/public/count.php +++ b/public/count.php @@ -4,4 +4,4 @@ $output .= $count . ' '; } -include 'count.html.php'; \ No newline at end of file +include '../count.html.php'; \ No newline at end of file From b401189b425d9cbe29f890f216c109b0ff08f217 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Sun, 15 Jan 2017 14:28:59 +0000 Subject: [PATCH 03/10] use __DIR__ --- public/count.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/count.php b/public/count.php index bf18560..ca6f38c 100644 --- a/public/count.php +++ b/public/count.php @@ -4,4 +4,4 @@ $output .= $count . ' '; } -include '../count.html.php'; \ No newline at end of file +include __DIR__ . '/../count.html.php'; \ No newline at end of file From e8e70b47afc73888316fcbe066c0a16d22bac908 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Wed, 4 Oct 2017 14:10:41 +0100 Subject: [PATCH 04/10] added sample switcher --- public/samples/index.php | 126 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 public/samples/index.php diff --git a/public/samples/index.php b/public/samples/index.php new file mode 100644 index 0000000..5eeb442 --- /dev/null +++ b/public/samples/index.php @@ -0,0 +1,126 @@ + +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +} +catch (PDOException $e) { + echo '

Could not connect to database. Did you delete the `homestead` user or change it\'s password?

'; + echo '

' . $e . '

'; + die; +} + + +try { + //sample user might not exist so the query may throw an exception, that's fine, ignore it. + try { + //Drop the user, there's a chance the password has been changed + $pdo->query('DROP USER \'ijdb_sample\'@\'localhost\''); + } + catch (PDOException $e) {} + + //Create the user for the sample code to use + $pdo->query('CREATE USER \'ijdb_sample\'@\'localhost\' IDENTIFIED BY \'mypassword\''); + + //Drop the database, only one sample should be used at once. + + $pdo->query('DROP DATABASE IF EXISTS ijdb_sample'); + + + $pdo->query('CREATE DATABASE ijdb_sample'); + $pdo->query('GRANT ALL PRIVILEGES ON ijdb_sample.* To \'ijdb_sample\'@\'localhost\''); + $pdo->query('FLUSH PRIVILEGES'); + $pdo->query('USE ijdb_sample'); + + if (file_exists('../../database.sql')) { + $pdo->exec(file_get_contents('../../database.sql')); + } + +} +catch (PDOException $e) { + echo 'Could not create sample database/user'; + echo $e->getMessage(); +} + + + + +if (isset($_GET['branch'])) { + exec('git checkout ' . $_GET['branch'], $n); +} +exec('git status', $output); + +$branchName = str_replace('On branch ', '', $output[0]); + +?> + + + <?= $branchName; ?> - PHP Nove to Ninja sample code + + + + + + + + +

PHP Novice to Ninja sample code

+ +

Click on a file to view in your browser

+ +
    + isDot()) continue; + if ($file->getFileName() == 'samples') continue; + + $code = file_get_contents('../' . $file->getFileName()); + echo '
  • ' . $file->getFileName() . ''; + + echo highlight_string($code, true); + echo '
  • '; + } + + ?> +
+ + +

View a different sample

+ + + + \ No newline at end of file From 5395fb3ccca7a083bf77cabb55e14457e49c39c5 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Thu, 5 Oct 2017 19:41:48 +0100 Subject: [PATCH 05/10] added sample switcher --- public/samples/index.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/samples/index.php b/public/samples/index.php index 5eeb442..a155bdc 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -110,12 +110,14 @@ - \ No newline at end of file + From 44ba16e74bedb38fa0816193f818aec6fa41c892 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Thu, 5 Oct 2017 20:21:22 +0100 Subject: [PATCH 06/10] updated sample switcher: supports custom samples --- public/samples/index.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/public/samples/index.php b/public/samples/index.php index a155bdc..aeaaae4 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -45,14 +45,23 @@ } - +exec('git status', $output); +$branchName = str_replace('On branch ', '', $output[0]); if (isset($_GET['branch'])) { - exec('git checkout ' . $_GET['branch'], $n); + exec('git status', $status); + $status = implode("\n", $status); + if (strpos($stauts, 'nothing to commit') !== false) { + $parts = explode('-Modified', $branchName); + $newBranchName = $parts[0] . '-Modified-' . date('Y-m-d H:i:s'); + + exec('git checkout -b "' . $newBranchName . '"'); + exec('git add .'); + exec('git commit -m "user modified sample"'); + } + exec('git checkout "' . $_GET['branch'] . '"', $n); } -exec('git status', $output); -$branchName = str_replace('On branch ', '', $output[0]); ?> From 32a85f87cf38f1450b282208d6c9fc44ad5ca2ed Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Thu, 5 Oct 2017 20:22:23 +0100 Subject: [PATCH 07/10] updated sample switcher: supports custom samples --- public/samples/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/samples/index.php b/public/samples/index.php index aeaaae4..e98fc83 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -51,7 +51,7 @@ if (isset($_GET['branch'])) { exec('git status', $status); $status = implode("\n", $status); - if (strpos($stauts, 'nothing to commit') !== false) { + if (strpos($status, 'nothing to commit') !== false) { $parts = explode('-Modified', $branchName); $newBranchName = $parts[0] . '-Modified-' . date('Y-m-d H:i:s'); From e18febb6293df309d08693a2f06a1b7f825cc3dc Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Thu, 5 Oct 2017 20:51:24 +0100 Subject: [PATCH 08/10] updated sample switcher: supports custom samples --- public/samples/index.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/public/samples/index.php b/public/samples/index.php index e98fc83..c90b231 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -1,6 +1,5 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -51,15 +50,30 @@ if (isset($_GET['branch'])) { exec('git status', $status); $status = implode("\n", $status); - if (strpos($status, 'nothing to commit') !== false) { - $parts = explode('-Modified', $branchName); - $newBranchName = $parts[0] . '-Modified-' . date('Y-m-d H:i:s'); + if (strpos($status, 'nothing to commit') == false) { + + + + $parts = explode('_Modified', $branchName); + $newBranchName = $parts[0] . '_Modified-' . date('Y-m-d-H.i.s'); + - exec('git checkout -b "' . $newBranchName . '"'); - exec('git add .'); - exec('git commit -m "user modified sample"'); + exec('git checkout -b ' . $newBranchName . ' 2>&1', $z); + + exec('git add -A 2>&1', $x); + exec('git commit -m "user modified sample" 2>&1', $y); + + var_dump($z); + var_dump($y); + var_dump($x); } exec('git checkout "' . $_GET['branch'] . '"', $n); + $branchName = $_GET['branch']; +} + +if (!isset($branchName)) { + exec('git status', $output); + $branchName = str_replace('On branch ', '', $output[0]); } @@ -120,14 +134,16 @@ ' . $branch . ''; } From dc067c741a76dd166cc9b0c18485560ff1878ed5 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Fri, 6 Oct 2017 12:43:53 +0100 Subject: [PATCH 09/10] updated sample switcher: supports custom samples --- public/samples/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/samples/index.php b/public/samples/index.php index c90b231..520fb00 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -141,6 +141,7 @@ $branch = trim($branch, " \t*"); $branch = str_replace('origin/', '', $branch); + $branch = str_replace('remotes/', '', $branch); $class =$branch == $branchName ? 'current' : ''; From 722fd93b31bcfe94280afedff91881ec9b7d003f Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Fri, 6 Oct 2017 12:57:43 +0100 Subject: [PATCH 10/10] updated sample switcher: supports custom samples --- public/samples/index.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/samples/index.php b/public/samples/index.php index 520fb00..a3dc2d4 100644 --- a/public/samples/index.php +++ b/public/samples/index.php @@ -136,6 +136,8 @@ exec('git branch -a', $branches); + $branchList = []; + foreach ($branches as $branch) { @@ -143,11 +145,19 @@ $branch = str_replace('origin/', '', $branch); $branch = str_replace('remotes/', '', $branch); + $branchList[$branch] = $branch; + + } + + foreach ($branchList as $branch) { $class =$branch == $branchName ? 'current' : ''; if ($branch == 'master') continue; echo '
  • ' . $branch . '
  • '; } + + + ?>