Skip to content

Commit dbd958e

Browse files
authored
Merge pull request #108 from php-school/problem-files-common-language
Problem files common language
2 parents a01e6dc + 19649ca commit dbd958e

File tree

12 files changed

+109
-72
lines changed

12 files changed

+109
-72
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercises/array-we-go/problem/problem.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ Write a program that takes an array of filepaths as arguments, filtering out fil
22

33
Finally output the basename of the files, each on a new line.
44

5-
The full path of the files to read will be provided as the command line arguments. You do not need to make your own test files.
5+
The full path of the files to read will be provided as command line arguments. You do not need to make your own test files.
66

77
----------------------------------------------------------------------
88
## HINTS
99

10-
Remember the first argument will be the programs file path and not an argument passed to the program.
10+
Remember, the first argument will be the programs file path and not an argument passed to the program.
1111

1212
You will be expected to make use of core array functions, `array_shift`, `array_filter` and `array_map`.
1313

1414
To check a file exists you will need to use `file_exists($filePath)`. This method will *return* a *boolean* `true` or `false`.
1515

16-
Documentation on the `SplFileObject` class can be found by pointing your browser here:
17-
[http://php.net/manual/en/class.splfileobject.php]()
16+
{{ doc 'SplFileObject' en class.splfileobject.php }}
1817

1918
----------------------------------------------------------------------

exercises/baby-steps/problem/problem.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ You can access command-line arguments via the global `$argv` array.
88
To get started, write a program that simply contains:
99

1010
```php
11+
<?php
1112
var_dump($argv);
1213
```
1314

15+
{{ cli }}
1416
Run it with `php program.php` and some numbers as arguments. e.g:
1517

1618
```sh
1719
$ php program.php 1 2 3
1820
```
1921

20-
In which case the output would be an array looking something like:
22+
{{ cli }}
23+
24+
{{ cloud }}
25+
Run it by pressing the `Run` button in the editor.
26+
{{ cloud }}
27+
28+
The output should be an array looking something like:
2129

2230
```php
2331
array(4) {
@@ -32,10 +40,15 @@ array(4) {
3240
}
3341
```
3442

35-
You'll need to think about how to loop through the number of arguments so you can output just their sum. The first element of the `$argv` array is always the name of your script. eg `program.php`, so you need to start at the 2nd element (index 1), adding each item to the total until you reach the end of the array.
43+
You'll need to think about how to loop through the number of arguments so you can output just their sum. The first element of the `$argv` array is always the name of your script. eg `solution.php`, so you need to start at the 2nd element (index 1), adding each item to the total until you reach the end of the array.
3644

3745
Also be aware that all elements of `$argv` are strings and you may need to *coerce* them into numbers. You can do this by prefixing the property with a cast `(int)` or just adding them. PHP will coerce it for you.
3846

39-
`{appname}` will be supplying arguments to your program when you run `{appname} verify program.php` so you don't need to supply them yourself. To test your program without verifying it, you can invoke it with `{appname} run program.php`. When you use `run`, you are invoking the test environment that `{appname}` sets up for each exercise.
47+
{{ cli }}
48+
{{ appname }} will be supplying arguments to your program when you run `{{ appname }} verify program.php` so you don't need to supply them yourself. To test your program without verifying it, you can invoke it with `{{ appname }} run program.php`. When you use `run`, you are invoking the test environment that {{ appname }} sets up for each exercise.
49+
{{ cli }}
4050

51+
{{ cloud }}
52+
PHP school will be supplying arguments to your program when you click `Verify` in the editor. To test your program without verifying it, you can just execute it by pressing the `Run` button in the editor.
53+
{{ cloud }}
4154
----------------------------------------------------------------------

exercises/concerned-about-separation/problem/problem.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
This problem is the same as the previous but introduces the concept of **classes**. You will need to create two files to solve this.
1+
This problem is the same as the previous but introduces the concept of **classes**. You will need to create two files to solve this problem.
22

33
Create a program that prints a list of files in a given directory, filtered by the extension of the files. The first argument is the directory name and the second argument is the extension filter. Print the list of files (one file per line) to the console.
44

5-
You must write a *class* file to do most of the work. The file must *define* a single class with a single function that takes **two** arguments: the directory name and the filename extension string in that order. The filename extension argument must be the same as what was passed to your program. Don't turn it into a regular expression or prefix with "." or do anything except pass it to your class method where you can do what you need to make your filter work.
5+
You must write a *class* in a file to do most of the work. The file must *define* a single class with a single function that takes **two** arguments: the directory name and the filename extension, in that order. The filename extension argument must be the same as what was passed to your program. Don't turn it into a regular expression or prefix with `.` or do anything except pass it to your class method where you can do what you need to make your filter work.
66

77
You **must** not print directly to the console from your class, only from your original program.
88

9-
The benefit of having a contract like this is that your class can be used by anyone who expects this contract. So your class could be used by anyone else who does learnyouphp, or the verifier, and just work.
9+
The benefit of having a contract like this is that your class can be used by anyone who expects this contract. So your class could be used by anyone else who attempts this exercise, or the verifier, and just work.
1010

1111
----------------------------------------------------------------------
1212
## HINTS
@@ -25,7 +25,7 @@ class DirectoryFilter
2525
}
2626
```
2727

28-
To use your new class in your original program file, use the `require_once` construct with the filename. So, if your file is named mymodule.php then:
28+
To use your new class in your original program file, use the `require_once` construct with the filename. So, if your file is named `mymodule.php` then use:
2929

3030
```php
3131
<?php
@@ -41,12 +41,7 @@ $myFilter = new DirectoryFilter;
4141

4242
You can then call the method you defined with its required arguments.
4343

44-
Documentation on class basics can be found here:
45-
46-
[http://php.net/manual/en/language.oop5.basic.php]()
47-
48-
Documentation on `require_once` can be found here:
49-
50-
[http://php.net/manual/en/function.require-once.php]()
44+
* {{ doc 'class basics' en language.oop5.basic.php }}
45+
* {{ doc require_once en function.require-once.php }}
5146

5247
----------------------------------------------------------------------

exercises/database-read/problem/problem.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ Display the information of all the users in the database table `users` whose age
44

55
`User: Jim Morrison Age: 27 Sex: male`
66

7-
Finally you will be given a random name as the second argument to your program, you should update the row in the `users` table which corresponds to this name. You should change the name to `David Attenborough`.
7+
Finally, you will be given a random name as the second argument to your program, you should update the row in the `users` table which corresponds to this name. You should change the name to `David Attenborough`.
88

99
----------------------------------------------------------------------
1010
## HINTS
1111

1212
This is an exercise introducing databases and PDO. PDO is a powerful abstraction library for dealing with different database vendors in a consistent manner. You can read the PDO manual here:
1313

14-
[http://php.net/manual/en/book.pdo.php]()
14+
[http://php.net/manual/en/book.pdo.php](http://php.net/manual/en/book.pdo.php)
1515

1616
A short introduction can be found here:
1717

18-
[http://www.phptherightway.com/#pdo_extension]()
18+
[http://www.phptherightway.com/#pdo_extension](http://www.phptherightway.com/#pdo_extension)
1919

2020
The most interesting class will be `\PDO`. The first parameter is the DSN string. The second and third are the username and password for the database. They are not needed for this exercise and can be left out.
2121

22-
The `users` table is structured as follows
22+
The `users` table is structured as follows:
2323

2424
```
2525
+----+-----------------+-----+--------+
@@ -40,11 +40,11 @@ foreach ($pdo->query('SELECT * FROM users') as $row) {
4040
}
4141
```
4242

43-
`$row` is now an array of data. The key will be the columns and the value is the database value
43+
`$row` is now an array of data. The key will be the column name and the value is the database value.
4444

4545

4646
You should use prepared statements to perform the updating. You should be most interested in the `prepare` and `execute` methods.
4747

48-
Remember the first argument will be the program's file path and not an argument passed to the program.
48+
Remember, the first argument will be the program's file path and not an argument passed to the program.
4949

5050
----------------------------------------------------------------------

exercises/dependency-heaven/problem/problem.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ The library works by accepting a PSR7 request and returns to you a PSR7 response
3838

3939
There are a few other components we need, in order to use `league/route`:
4040

41-
* **laminas/laminas-diactoros** - For the PSR7 requests and responses.
42-
* **laminas/laminas-httphandlerrunner** - For outputting the PSR7 response to the browser.
41+
* `laminas/laminas-diactoros` - For the PSR7 requests and responses.
42+
* `laminas/laminas-httphandlerrunner` - For outputting the PSR7 response to the browser.
4343

4444
`laminas/laminas-diactoros` is a PSR7 implementation. PSR's are standards defined by the PHP-FIG, a committee of PHP projects, attempting to increase interoperability in the PHP ecosystem. PSR7 is a standard for modelling HTTP requests. We can use the `laminas/laminas-diactoros` package to marshal a PSR7 request object from the PHP super globals like so:
4545

@@ -91,9 +91,15 @@ Finally, you will also be required to use `symfony/string` to manipulate the dat
9191
----------------------------------------------------------------------
9292
## HINTS
9393

94+
{{ cli }}
9495
Point your browser to [https://getcomposer.org/doc/00-intro.md](https://getcomposer.org/doc/00-intro.md) which will walk you through **Installing Composer** if you haven't already!
9596

96-
Use `composer init` to create your `composer.json` file with interactive search.
97+
Use `composer init` to create your `composer.json` file with interactive search.
98+
{{ cli }}
99+
100+
{{ cloud }}
101+
Composer is installed and ready to go on cloud, use the `Composer Deps` button in the editor to search for and install your dependencies. While you should read the documentation for [Composer](https://getcomposer.org/doc/00-intro.md), it's important to note that the way we manage dependencies on PHP School cloud, is not how you would manage them in your own projects. We abstract away the `composer.json` file to keep it simple.
102+
{{ cloud }}
97103

98104
For more details look at the docs for...
99105

exercises/exceptional-coding/problem/problem.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ Every file should exist but under exceptional circumstances some files may not.
66
Unable to open file at path '/file/path'
77
```
88

9-
The full path of the files to read will be provided as the command line arguments. You do not need to make your own test files.
9+
The full path of the files to read will be provided as command line arguments. You do not need to make your own test files.
1010

1111
----------------------------------------------------------------------
1212
## HINTS
1313

14-
You are urged to use `try... catch` logic here along with the SplFileObject contruct which throws a `RuntimeException` when a file does not exist.
14+
You are urged to use `try... catch` logic here along with the `SplFileObject` contruct which throws a `RuntimeException` when a file does not exist.
1515

16-
Documentation on the `SplFileObject` class can be found by pointing your browser here:
17-
[http://php.net/manual/en/class.splfileobject.php]()
16+
{{ doc SplFileObject en class.splfileobject.php }}
1817

1918
----------------------------------------------------------------------
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
Create a program that prints a list of files in a given directory, filtered by the extension of the files. You will be provided a directory name as the first argument to your program (e.g. '/path/to/dir/') and a file extension to filter by as the second argument.
1+
Create a program that prints a list of files in a given directory, filtered by the extension of the files. You will be provided a directory name as the first argument to your program (e.g. `/path/to/dir/`) and a file extension to filter by as the second argument.
22

3-
For example, if you get 'txt' as the second argument then you will need to filter the list to only files that **end with .txt**. Note that the second argument _will not_ come prefixed with a '.'.
3+
For example, if you get `txt` as the second argument then you will need to filter the list to only files that **end with .txt**. Note that the second argument _will not_ come prefixed with a full stop (`.`).
44

5-
The list of files should be printed to the console, one file per line.
5+
The list of files should be printed out, one file per line.
66

77
----------------------------------------------------------------------
88
## HINTS
99

10-
The `DirectoryIterator` class takes a pathname as its first argument. Using an iterator in a `foreach` loop will provide you with a `SplFileInfo` object for each file.
10+
The `DirectoryIterator` class takes a pathname as its first argument.
11+
12+
Using an iterator in a `foreach` loop will provide you with a `SplFileInfo` object for each file.
1113

1214
```php
1315
<?php
@@ -16,13 +18,10 @@ foreach (new DirectoryIterator('/some/path') as $file) {
1618
}
1719
```
1820

19-
Documentation on the `SplFileInfo` class can be found by pointing your browser here:
20-
21-
[http://php.net/manual/en/class.splfileinfo.php]()
21+
{{ doc SplFileInfo en class.splfileinfo.php }}
2222

23-
You may also find `SplFileInfo`'s `getExtension()` method helpful
23+
You may also find `SplFileInfo`'s `getExtension()` method helpful.
2424

25-
Documentation on the `getExtension()` method can be found by pointing your browser here:
26-
[http://php.net/manual/en/splfileinfo.getextension.php]()
25+
{{ doc getExtension() en splfileinfo.getextension.php }}
2726

2827
----------------------------------------------------------------------

exercises/hello-world/problem/problem.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@ Write a program that prints the text "Hello World" to the console (stdout).
22

33
----------------------------------------------------------------------
44
## HINTS
5-
5+
{{ cli }}
66
To make a PHP program, create a new file with a `.php` extension and start writing PHP! Execute your program by running it with the
77
`php` command. e.g.:
88

99
```sh
1010
$ php program.php
1111
```
12+
{{ cli }}
13+
14+
{{ cloud }}
15+
16+
We've created you an empty file, look in the file tree for `solution.php`. That's your starting point.
17+
18+
We'll execute your solution file for you when you press the `Run` or `Verify` buttons. The `Run` button simply runs your program and captures the output, displaying it for you to view. The `Verify` button runs your program but performs some extra tasks, such as comparing the output, checking for certain structures and function calls, etc. It then displays the result of those verifications.
19+
20+
Both `Run` and `Verify` execute your program with random inputs which are determined by the current exercise. For example one exercise might generate a bunch of numbers to pass to your program, where another one might pass you a JSON encoded string.
21+
22+
{{ cloud }}
1223

1324
You can write to the console from a PHP program with the following code:
1425

@@ -17,9 +28,11 @@ You can write to the console from a PHP program with the following code:
1728
echo "text";
1829
```
1930

20-
The first line tells the PHP to interpret the code following it. It is required before any PHP code is written. Read more here: [http://php.net/manual/en/language.basic-syntax.phptags.php]()
21-
The second line is the instruction to print out some text.
31+
The first line tells PHP to interpret the code following it. It is required before any PHP code is written. The second line is the instruction to print out some text.
32+
33+
{{ doc 'PHP tags' en language.basic-syntax.phptags.php }}
2234

35+
{{ cli }}
2336
Place the code in to a text file using your favourite text editor, some popular editors are listed below:
2437

2538
* Sublime Text: [https://www.sublimetext.com/]()
@@ -30,19 +43,32 @@ Switch back to the terminal and run your code again with the same command as abo
3043
```sh
3144
$ php program.php
3245
```
46+
{{ cli }}
47+
48+
{{ cloud }}
49+
Try pressing the `Run` button in the bottom right corner to execute your program.
50+
{{ cloud }}
3351

3452
You should see the word "text" printed out on the console.
3553

36-
Now you must adapt the code to pass the challenge presented. Remember the challenge was: Write a program that prints the text "Hello World" to the console (stdout).
54+
Now you must adapt the code to pass the presented challenge. Remember, the challenge was: Write a program that prints the text "Hello World" to the console.
3755

56+
{{ cli }}
3857
We have created you a file named `hello-world.php` in your current working directory, feel free to use it!
58+
{{ cli }}
3959

40-
When you have finished and saved the file you must run the following (substituting program.php to the name of the file you created which contains your code)
60+
{{ cli }}
61+
When you have finished editing your program and saved the file you must run the following (substituting program.php to the name of the file you created which contains your code)
4162

4263
```sh
4364
$ {appname} verify program.php
4465
```
66+
{{ cli }}
67+
68+
{{ cloud }}
69+
When you have finished editing your program you must verify it. Click the `Verify` button in the bottom right corner.
70+
{{ cloud }}
4571

46-
to proceed. Your program will be tested, a report will be generated, and the lesson will be marked 'completed' if you are successful.
72+
Your program will be tested, a report will be generated, and the lesson will be marked 'completed' if you are successful.
4773

4874
----------------------------------------------------------------------

0 commit comments

Comments
 (0)