File tree Expand file tree Collapse file tree 9 files changed +147
-1
lines changed Expand file tree Collapse file tree 9 files changed +147
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ RUN docker-php-ext-install mysqli pdo_mysql
99# Get latest Composer
1010COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
1111
12+ COPY ./public /var/www
1213# Set working directory
1314WORKDIR /var/www
1415COPY ./public /var/www/public
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 44$ scanned_directory = array_diff (scandir ($ directory ), array ('.. ' , '. ' ));
55foreach ($ 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}
1010try {
You can’t perform that action at this time.
0 commit comments