Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by ignace

  1. 1) You are declaring a class Shape but you are not using it? 2) You have one class Shape to represent all your shapes shows you haven't been paying attention in math 101 because assuming that for the squares and rectangle you have a method getSides() then what do you return for a circle? Similarly what do you return for getRadius() on a square? You already have the form you simply have to add some validation and add the proper classes. For File I/O you can create a simple File object. Take a look here for the functions required to perform file operations: http://php.net/manual/en/book.filesystem.php I have no idea what is meant with collection of shapes perhaps a simple array? $shapes = array( new Circle($radius), new Square(), new Rectangle(), );But as since these have no common ancestors it's hard to iterate over them and execute something meaningful on them.
  2. $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1; $items_per_page = 20; $offset = ($current_page - 1) * $items_per_page; $items = glob("entries/*.php"); $total_items = count($items); $total_pages = ceil($total_items / $items_per_page); foreach (array_slice($items, $offset, $items_per_page) as $entry) { include $entry; }
  3. You may have noticed the number of competitors on the internet has increased and we are not a commercial entity as such we don't have the green like some of our competitors have.
  4. Simply do the checks inside Device and throw an exception when an invalid value is encountered. try { $device = new Device($foo, $bar); } catch (InvalidArgumentException $e) { echo 'I see what you did there!'; }It's the responsibility of the programmer to write the class that the invariants are intact ALWAYS.
  5. To understand this, you need to understand what authentication is. It is your application acknowledging he knows the User. The mechanism used to verify this fact may differ thus meaning that each time you add a new authentication mechanism (twitter, facebook, restful API, ..) you would need to alter your User object which violates the Single Responsibility Principle which states that an object should have only one reason to change while when you couple it with authentication it needs to change whenever you need to make changes to the User class or when your authentication mechanism changes. This should be really obvious. $_SESSION only exists when using your application over HTTP, as soon as you start using it across other platforms it is no longer available.
  6. I disagree. 1) The User object should not be aware of the database. 2) Login is not a User concern, but an application concern so it should be handled by the application or a service. 3) $_SESSION is also an application concern and should not be used inside User. 4) Your User object is nothing more but a simple data container (set/get) so you end up with code like: if ($user->getSomething() == 'somethingelse') $user->setSomethingElse('toSomething');If the object owns the data, then it should control all actions done to it. Let's take it from the beginning. At the start your client only asks for a quote to do a job for him: $request = $client->askQuote('task description'); // { return new RequestForQuote($this, $description); } $repo->persist($request);To which you create a quote and reply your client: $quote = $request->createQuote($dateStart, $workHours, $price); // { return new Quote($this->client, $this->description, $dateStart, $workHours, $price); }Which your client accepts/rejects: $job = $client->accept($quote); // { return $quote->won(); } $repo->persist($job); $client->reject($quote, $reason); // { return $quote->lost($reason); }I think you get the point.
  7. You are not the only spy here
  8. Perhaps reading documentation instead of complaining: http://symfony.com/doc/current/cookbook/templating/global_variables.html
  9. It's not complete, and it needs a few more reviews but this might work: class Grid { private $rows; private $cols; public function getHouseAt(Position $pos) {} } class House { private $pos; private $owner; public function updatePlayerPosition($player) { if (!$this->owner->equals($player)) { throw new InvalidArgumentException('Out, Out I tell you!'); } $player->setPosition($this->pos); } } class Travel { private $distance; private $direction; public function getNewPosition($from) {} } class Position { private $x; private $y; } interface PositionAwareInterface { public function setPosition(Position $pos); public function getPosition(); } class Player implements PositionAwareInterface { private $pos; public function goInside($house) { $house->updatePlayerPosition($this); } } class PlayerTravelService { public function move(Player $player, Travel $path) { switch ($path->getDistance()) { case 0: return; // no-op case 1: $this->doMove($player, $path); break; default: throw new UnexpectedValueException('Player can only travel along neighbouring squares.'); } } private function doMove(Player $player, Travel $path) { $pos = $path->getNewPosition($player); if (!($house = $this->grid->getHouseAt($pos))) { throw new UnexpectedValueException('Travel aborted. Nothing there!'); } $player->goInside($house); } }It tries to model your domain from a code point of view. I suppose CQRS would work really well here. You basically would have a TravelCommand with the coordinates and the TravelCommandHandler would handle the actual travel as it would update your model.
  10. You don't need to do any fancy geo-location as google automatically detects (and for SEO you should tell them all your domains to avoid duplicate content penalty) the location of the server and the extension and users from those countries will automatically see your website for that specific country.
  11. We are gonna need some more information then you simply stating it has to do with MySQL. What exactly?
  12. fopen fgetcsv fclose It will open a file handler to the file (without reading it's contents into memory) then using a while read a line and parse as csv and return it as an array for you to process. Very memory efficient.
  13. 300mb memory and you use 20-27 virtual cores. Clearly someone has got it wrong. Either the amount of virtual cores is lower or the memory consumption is higher. Also using that many cores would cost an insane amount of money and they would never allow anyone to scale up like that unless you paid for it. So, my guess is that your website has outgrown what shared hosting can offer, which is not that hard knowing there could be like minimum 64 websites on one machine (some ignore the limits of the server altogether and simply keep adding websites until it fails to boot due to insufficient ram figuratively speaking). So, you either need to buy a virtual dedicated, or a dedicated server. Or use cloud hosting, so you pay less on quiet periods, and more (with a max.) on heavy traffic.
  14. Pretty much everyone follows the PSR standards: http://www.php-fig.org/ So #2 would be the way to go.
  15. With the skills listed I find it very hard to believe you can't find any work. Which makes me ponder about your attitude. Clearly you like to show-off, but who doesn't, though I wouldn't go telling everyone you went to jail for exploiting a security vulnerability. HR only hears jail. Are you an independent contractor or looking for full employment? The company I work for recently hired someone from peopleperhour.com. Perhaps you can add yourself to a few of these websites. You say you don't have any portfolio. Start by creating a website about yourself and that you are available for hire. This way you may get unexpected job offers. Look for companies that interest you and give them a call. Telling them you want to work there, they find more attractive then when someone pops-in after they have waved a looking-to-hire sign.
  16. Your Join class does too much work, you need to delegate the work between classes and let them each handle their job: <?php namespace My\Model\Entity; { use My\Model\Entity\ValueObject\Email; use My\Model\Entity\ValueObject\Password; // represents a User in the system class User { private $id; private $fname; private $lname; private $email; private $password; public function setId($id) { $this->id = $id; return $this; } public function setFirstName($id) { $this->fname = $id; return $this; } public function setLastName($id) { $this->lname = $id; return $this; } public function setEmail(Email $id) { $this->email = (string) $id; return $this; } public function setPassword(Password $id) { $this->password = (string) $id; return $this; } public function getId() { return $this->id; } public function getFirstName() { return $this->fname; } public function getLastName() { return $this->lname; } public function getEmail() { return $this->email; } public function getPassword() { return $this->password; } } } namespace My\Model\ValueObject { // holds a password, makes sure it's valid, // is passed around between objects without having to check if it's valid, it is! class Password { } // holds an e-mail address, makes sure it's valid // is passed around between objects without having to check if it's valid, it is! class Email { } } namespace My\App { // persists state for a user between requests class Session { } } namespace My\DataStore\DataMapper { use PDO; // performs the mapping of a user to a record in the database and vice versa // translates a record in the database to a User object. class UserDataMapper { private $database; public function __construct(PDO $pdo) { $this->database = $pdo; } public function insert(User $user) { $stmt = $this->database->prepare('INSERT INTO users (id, fname, lname, email, password) VALUES (NULL, :fname, :lname, :email, :password)'); $stmt->bindValue(':fname', $user->getFirstName()); $stmt->bindValue(':lname', $user->getLastName()); $stmt->bindValue(':email', $user->getEmail()); $stmt->bindValue(':password', $user->getPassword()); $stmt->execute(); $user->setId($this->database->lastInsertId()); return true; } public function update(User $user) {} public function delete(User $user) {} } }So that you can combine them to: namespace My\Model\Service { // sends a specific e-mail class SendUserRegistrationMailerService { } // creates a new user in the system // notifies the user and requests him to verify his e-mail address if necessary // works with other services to achieve it's goal class RegisterUserService { private $session; private $userRegistrationMailer; private $userDataMapper; public function registerUser(..) { $user = new User(..); $this->userDataMapper->insert($user); $this->userRegistrationMailer->sendUserRegistrationMail($user, $this->emailVerificationRequired); $this->session->createAuthSession($user); } } }
  17. $data = $StockMarketAPI->getData(); echo $data['price'];
  18. From what I gather from your posts, this contains your missing puzzle pieces: function http_json_post($url, $data) { $ch = curl_init($url); curl_setopt_array($ch, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $data_string = json_encode($data), // your data in JSON: {"name":"JTapp","age":"50"} CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', // tell the server we are sending it JSON 'Content-Length: ' . strlen($data_string)) // tell it how long it is ) )); $output = curl_exec($ch); curl_close($ch); return $output; } $webservice_url = 'http://webservice.local/data.json'; // actual API URL $result = http_json_post($webservice_url, array('name' => 'JTapp', 'age' => 50));If this does not work, then state the returned error.
  19. Who the hell are you that we should simply believe you? Good. If our elitist attitudes make you a better programmer, then I applaud us in general and .josh specific.
  20. To verify it works as expected. It's also used to replicate bugs, the fix will make the test pass and thus fixes the bug. Of course this is assuming the programmer responsible wrote good tests. All you have verified is that the Compound model does not return Product models and it doesn't so your understanding of the problem is wrong. So, perhaps you should review your code and find what is really going on and then write a new test matching your new findings and make sure the test fails (meaning you replicated the bug in your test). Then make your changes to your code and the end-result should be that your test succeeds.
  21. You could have mentioned the source: http://stackoverflow.com/a/2445332 Clearly homework, or do you really think we believe you work with somebody who is capable to create an API while you fail to write a line of PHP code that actually works.. Not to mention he would probably have given you some sample code. Even your OP uses code from your post you made last year: http://forums.phpfreaks.com/topic/280829-search-using-metode-cant-trim-help-please/ which according to you should suffice in making us believe this has somehow something to do with the API. Also the code in your OP is full of contradictions because programmers are one thing above all: consistent. They don't use the hungarian notation in one instance and then do something else entirely in another. And since the hungarian notation is quite popular among teachers and not so much among developers further increases the likelihood this is a course assignment. Another thing, EVERYONE here has Chrome installed, and Firefox, and Safari, and Opera, and has VM's of WinXP, WinVista, Win7 to test IE6 through IE10. It's part of being a webdeveloper which if you were employed as one would have known. Don't lie, simply state you have trouble completing your homework and someone on here might actually help you/do it for you. Sorry for the rant but I REALLY don't like being lied to.
  22. What this means is that your User should not be aware of $_SESSION, $_COOKIE, $_POST, .. because if it does this means it is no longer re-usable in a different environment for example a REST API, CLI, .. Also logging in has very little to do with the User itself, and more with the visitor representing that User, although an admin could represent ANY User. At the very basic level we can consider something like this: $_SESSION['loggedin'] = true;And no User is involved. Same for logout: unset($_SESSION['loggedin']);Registration is nothing more then simply creating a new record in your database which is synonymous to new User(..). In the example of a REST API (using an API key), login has a different meaning then in your app (using a login form). Which is why it is an application concern and not a domain concern.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.