Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. LIMIT 2, 4 http://dev.mysql.com/doc/refman/5.1/en/select.html
  2. The RegistrationForm extends FormCollection and is therefor an instance of FormCollection this means that RegistrationForm will have all methods of FormCollection inherited. RegistrationForm(new Validator()) is a bad idea because you have no assurance that the data will actually be validated like for example if you by accident pass the wrong validator therefor the validator should be part of the internals of RegistrationForm. True. You can't instantiate an abstract class or an interface. Because if the concrete class doesn't specify one the parent's constructor get's executed. True. You can only assign scalar types to a class variable, you can also use constant's because they can only hold scalar types.
  3. Yes which means fly() and float() are obsolete. program to an interface, not an implementation
  4. Namespaces also allows for monkey patching: namespace Foo\Bar; function strlen($str) { return 3; } All code run under this namespace will return 3 as a strlen() result.
  5. This violates the Liskov Substitution Principle as the concrete class is not substitutable for it's parent. function fcukA(Duck $duck) { $duck->fly(); // only works with the MallardDuck }
  6. 1) Yes. 2) Only if they are declared abstract, everything else is inherited. 3) Only an abstract class allows you to define a body for a method (for example define an interface method)
  7. It depends on the font typeface: serif sans-serif monospace .. http://en.wikipedia.org/wiki/List_of_typefaces
  8. It isn't so complex, your really making this way harder then it should be. On the bright side your FormHandler is going the right way except it should be a base class/interface of some sort. When we look at a form we see that it either maps indirectly to a table or maps indirectly to multiple tables. The first case is simple and an ActiveRecord would suffice. The second case is more difficult as you want a single entry point which communicates with many sub-system components/models. So IMO the second case would be better suited with the Facade pattern.
  9. You can use xdebug which can generate a cachegrind file for you which you can look at with webcachegrind.
  10. Unfortunately no. On the bright sight though Zend framework already implements this with it's Zend_File component and contains some documentation. What I tried to get at is this: you write your code on a per-case basis something like: source: http://www.blazonry.com/scripting/upload-size.php if (is_uploaded_file($imgfile)) { $newfile = $uploaddir . "/" . $final_filename"; if (!copy($imgfile, $newfile)) { // if an error occurs the file could not // be written, read or possibly does not exist print "Error Uploading File."; exit(); } } /*== where storing tmp img file ==*/ $tmpimg = tempnam("/tmp" "MKPH"); $newfile = "$uploaddir/scaled.jpg"; /*== CONVERT IMAGE TO PNM ==*/ if ($ext == "jpg") { system("djpeg $imgfile >$tmpimg"); } else { echo("Extension Unknown. Please only upload a JPEG image."); exit(); } /*== scale image using pnmscale and output using cjpeg ==*/ system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$newfile"); However this only works for this particular case and copying this code to a new project with slight variations in the upload process means it needs to be amended (possibly also for each new case) until at the end you are copy-pasting from so many projects.. What I tried to explain to you is slice this code up into distinct parts and put these into separate classes, this way you can assemble your code (instead of copy-pasting it from many sources) like: $upload = new Upload($_FILES['upload']); $upload->attach(new FileMask('.jpg|.png|.gif')); // only allow jpg, png, and gif $upload->attach(new ScaleImageTo('50%', $removeOriginal)); // scale them down to 50% $upload->attach(new ConvertToJpeg()); $upload->uploadTo('/directory'); This would go in place of the above code. So instead of hard-coding (like the above example) your code, you can change/assemble your code at run-time.
  11. $upload = new Uploader(); $upload->attach(new ImageUploader('.jpg|.png|.gif')) ->attach(new ImageThumbnailer('50%')) ->execute('/directory'); The upload process varies depending on your context (images, documents, ..) all with different rules (thumbnail to .., remove original, ..), capturing these variations into separate classes leads to MANY non-reusable classes instead you should assemble your implementation. I used the Observer pattern as a simple example but the Decorator pattern is better suited for this process.
  12. Yup. It should be noted that views are only present in a Model-View-Controller (MVC) architecture, so why you are required to mix patterns is also beyond me. Is this for class?
  13. Why you used the Command pattern in a web environment to handle your requests is beyond me, MVC is much better suited. Well this is application logic and as such should be handled in the application, that is in your Controller (or in your case the Command). It could be something like: function doExecute(DeleteRequest $request) { if($request->isConfirmed()) { .. } }
  14. Isn't it annoying for you to always have to speak through my voice?
  15. At least my English teacher can be rest assured that she did a good job on the writing part Not sure how Stevie Hawkins sounds but I'm not that old
  16. Indeed those 2 tables were just to answer your questions. Correct. Yup. You can create a dropdown from the values in your jobs_types table: <option value="<?php print $row['id']; ?>"><?php print $row['name']; ?></option>
  17. Yes, it should all go into different tables. jobs (id, type_id, ..) jobs_types (id, ..) In jobs_types you add Account, Business, Customer Service as individual rows. To create a job about Customer Service insert it like: INSERT INTO jobs (1, 3, ...) Assuming 3 is the ID of Customer Service.
  18. You are overwriting $name on each turn. It should be: $name[$last . ', ' . $first][] = $schedule;
  19. Use a framework instead of rolling your own. Send makes no sense and Validate is too general. class SomeController extends Zend_Controller_Action { function someAction() { $form = new SomeForm(); if($this->_request->isPost()) { if($form->isValid()) { $form->process(); } } $this->view->form = $form; } } An example in Zend framework
  20. Euhm it seems like you are looking for a WYSIWYG editor, try: http://ckeditor.com/. You can use the onclick event of the div to change the div into an editor. CKEditor works on both textarea as normal html elements.
  21. Add an @copyright Ignace comment line above each function
  22. Take a look at http://html5demos.com/contenteditable. At the very least they'll have the necessary JS to edit your post. I personally tried on IE7 through 9 and FF.
  23. Do you use SCRUM? Are you satisfied with it? Been an improvement since you started using it? Are you a SCRUM-Master?
  24. function calc_next_day($day, $month, $year) { // 0 = January $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $day_count = $days_in_month[$month - 1]; if($day + 1 > $day_count) { $day = 1; if($month + 1 > 12) { $month = 1; ++$year; } else { ++$month; } } else { ++$day; } return "$day/$month/$year"; } function str_occur($string) { $string = preg_replace('/[^a-z]/i', '', $string); $string = str_split($string); return array_count_values($string); } A fun exercise You really can't do anything with it as they'll ask you questions about the code and you'll still end up screwed
×
×
  • 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.