-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Php examples #66
base: master
Are you sure you want to change the base?
Php examples #66
Conversation
I am going to complete all examples in PHP, because that is my primary language for developing. The directory structure allows for other languages to be added by other people, if they want. Personally, I think examples in Java, C++ and Python would be the most useful, but I leave that to the judgement of others :) |
…concept more clearly.
I think having examples in various languages would be very helpful. I'd be willing to write a few as well, if this becomes a thing. |
.gitignore
Outdated
@@ -0,0 +1,5 @@ | |||
# IntelliJ project files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntelliJ files dont belong here, They should be in you global gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically speaking, also correct. The file can be deleted as such, since it really doesn't serve any purpose in the repo anyway. Tnx
$paypal->setNext($bitcoin); | ||
|
||
// Let's try and pay our bill. | ||
$bank->pay(259); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add newlines at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, actually never knew about that one :) Tnx. I'll update when I have the chance :
http://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
{ | ||
if ($this->authenticate($password)) { | ||
$this->door->open(); | ||
echo 'Access granted!' . PHP_EOL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it makes more sense if firstly you echo 'Access granted' then open the door :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, will fix
@@ -0,0 +1,17 @@ | |||
<?php | |||
|
|||
require_once __DIR__ . '/autoload.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use composer to set psr-4 and avoid put this line everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, but as far as I'm concerned, I tried to make these examples as such that they are not dependent on Composer or any such 'mechanism', hence why I wrote my own little autoloader.
I might rework this to only have one autoload.php, but at the time I was thinking that maybe people wanted to test one set of examples, that is why I used the require_once on each of the examples.
Soooooo, it would seem I am finished with the PHP examples. I hope this inspires others to do the same in their preferred language. Excuses the delays, I am currently moving to a new employer and spare time is quite rare ATM. Suggestions are still welcome, perhaps I will try to write the examples in another language mysel (JS has popped up quite a lot in the issue queue lately). |
Hello,
Love the work already done in explaining the different design patterns, well done.
I also thought that including examples in different languages would help others (and myself) to better understand these patterns : sometimes people learn by just following along in their favourite IDE, debugging the code.
I hereby present you the first batch of examples, written in PHP.
I've sorted everything and added a small autoloader, so the examples should be just Plug and Play. People can call the scripts in a webbrowser or just use the CLI to run the script.
At the moment they've been written using PHP 5.6 (I know... sorry :) ), so all PH7 specifics are either left out or commented using Docblocks. Nothing is added by me to your examples (except namespacing for the autoloader).
I'll continue work on the other examples and hope this will tempt others to do the same in other languages.