Skip to content

Commit 3d9d51d

Browse files
author
gunnard
committed
merged
2 parents df34e03 + c1ca3be commit 3d9d51d

File tree

9 files changed

+147
-1
lines changed

9 files changed

+147
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN docker-php-ext-install mysqli pdo_mysql
99
# Get latest Composer
1010
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
1111

12+
COPY ./public /var/www
1213
# Set working directory
1314
WORKDIR /var/www
1415
COPY ./public /var/www/public

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313

1414
# MySQL database service
1515
db:
16+
platform: linux/x86_64
1617
image: mysql:8.0
1718
container_name: mysql-db
1819
ports:

public/chapter2/abstract.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
// Parent class
3+
abstract class Candy {
4+
public $name;
5+
public function __construct($name) {
6+
$this->name = $name;
7+
}
8+
abstract public function slogan() : string;
9+
}
10+
11+
// Child classes
12+
class Skittle extends Candy {
13+
public function slogan() : string {
14+
return "$this->name! - Taste the rainbow!\n";
15+
}
16+
}
17+
18+
class Twix extends Candy {
19+
public function slogan() : string {
20+
return "$this->name - Which side are you?\n";
21+
}
22+
}
23+
24+
class KitKat extends Candy {
25+
public function slogan() : string {
26+
return "$this->name - Gimmie a break!\n";
27+
}
28+
}
29+
30+
// Create objects from the child classes
31+
$skittle = new Skittle('Skittles');
32+
print $skittle->slogan();
33+
34+
$kitkat = new KitKat('KitKat');
35+
print $kitkat->slogan();
36+
?>
37+

public/chapter2/index.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
$directory = '/var/www';
4+
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
5+
foreach ($scanned_directory as $directory) {
6+
if (is_dir('/var/www/'.$directory)) {
7+
echo '<a href="'.$directory.'"><h2>'.$directory.'</h2></a><br />';
8+
}
9+
}
10+
try {
11+
echo '<br />';
12+
echo 'Current PHP version: ' . phpversion();
13+
echo '<br />';
14+
15+
$host = 'db';
16+
$dbname = 'database';
17+
$user = 'user';
18+
$pass = 'pass';
19+
$dsn = "mysql:host=$host;dbname=$dbname;charset=utf8";
20+
$conn = new PDO($dsn, $user, $pass);
21+
22+
echo 'Database connected successfully';
23+
echo '<br />';
24+
} catch (\Throwable $t) {
25+
echo 'Error: ' . $t->getMessage();
26+
echo '<br />';
27+
}

public/chapter2/namespace.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
Namespace Pants;
3+
4+
Class PantsMaker {
5+
6+
Public function pantsLabel($size, $color, $name) {
7+
$label = "These pants are size: $size, color: $color named: $name";
8+
Return $label;
9+
}
10+
}
11+
12+
$thesePants = new PantsMaker();
13+
Echo $thesePants->pantsLabel('12','blue','leeevi');
14+

public/chapter2/trait.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
trait userFunctions {
3+
Public function message1() {
4+
print "user message1\n";
5+
}
6+
}
7+
8+
Class UserClass {
9+
Use userFunctions;
10+
}
11+
12+
Class UserClass2 {
13+
Use userFunctions;
14+
}
15+
$user = new UserClass();
16+
$user->message1();
17+
18+
$user2 = new UserClass2();
19+
$user2->message1();
20+

public/chapter3/index.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
$directory = '/var/www';
4+
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
5+
foreach ($scanned_directory as $directory) {
6+
if (is_dir('/var/www/'.$directory)) {
7+
echo '<a href="'.$directory.'"><h2>'.$directory.'</h2></a><br />';
8+
}
9+
}
10+
try {
11+
echo '<br />';
12+
echo 'Current PHP version: ' . phpversion();
13+
echo '<br />';
14+
15+
$host = 'db';
16+
$dbname = 'database';
17+
$user = 'user';
18+
$pass = 'pass';
19+
$dsn = "mysql:host=$host;dbname=$dbname;charset=utf8";
20+
$conn = new PDO($dsn, $user, $pass);
21+
22+
echo 'Database connected successfully';
23+
echo '<br />';
24+
} catch (\Throwable $t) {
25+
echo 'Error: ' . $t->getMessage();
26+
echo '<br />';
27+
}

public/chapter3/sloppy.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
function getUser($id = null) {
4+
if ($id) {
5+
return $id;
6+
} else {
7+
return rand();
8+
}
9+
}
10+
11+
$user = getUser();
12+
13+
Function showUserName() {
14+
$user = getUser(4);
15+
var_dump($user);
16+
}
17+
var_dump($user);
18+
showUserName();
19+

public/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
55
foreach ($scanned_directory as $directory) {
66
if (is_dir('/var/www/'.$directory)) {
7-
echo '<a href="'.$directory.'">'.$directory.'</a>';
7+
echo '<a href="http://localhost:8000/'.$directory.'"><h2>'.$directory.'</h2></a><br />';
88
}
99
}
1010
try {

0 commit comments

Comments
 (0)