Jump to content

ignace

Moderators
  • Posts

    6,448
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by ignace

  1. Don't bother basing yourself on brand. There are cheaper brands that have the same quality as the expensive ones. If you know what to look for. Don't know much about the US market, but in the EU all tires have a label about noise, fuel consumption, and handling in rain. Also buy all season tires which are runflat and spend some more. Or you would either need to buy 8 rims or go every season changing tires on your rims. The runflat will make sure that in case of a flat tire you don't damage your rims while being able to drive to your nearest mechanic instead of calling and waiting for towing. It looks like this:
  2. Hello and welcome! I looked up your framework and it's really dated. I also fail to see how it leverages open-source. It doesn't use any of the readily available open-source components. It doesn't even use any of the standards like PSR, or composer, or dotenv, ..
  3. The slides already specify the design. You have a set of parameters that are passed to different strategies (see Strategy Pattern).
  4. ignace

    NYPVTT

    You don't have the clearance level to look in the locked box Seriously though I have no idea what NYPVTT is. I looked it up and a bunch of CIA related stuff popped up hence my comment.
  5. ignace

    NYPVTT

    Lifetime imprisonement for sure. Worst case you get shipped to a country/state where the death sentence is still allowed.
  6. Yes. Your field name should explain it's value: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add( 'game', EntityType::class, [ 'class' => 'AppBundle:Game', 'choice_label' => 'name', 'label' => 'name' ] ) ->add( 'type', EntityType::class, [ 'class' => 'AppBundle:Type', 'choice_label' => 'name', 'multiple' => false, 'expanded' => false ] ); } Afterwards you can access these fields like: $form->get('game') // and $form->get('type')
  7. Use the EntityType: https://symfony.com/doc/current/reference/forms/types/entity.html
  8. Shots fired!
  9. You can create an interface for every class in the hierarchy, but that's not really useful. An interface is a type hint essentially. So when you create specialised interfaces there must be a type hint for it in your code to be useful.
  10. Hi, I'm writing a script that scans images for numberplate edges in different angles. The below script works and picks up the edges in ~2 seconds. I'm curious if I can improve this to find the edges even faster. real 0m1.917s user 0m1.767s sys 0m0.125s <?php require __DIR__ . '/../vendor/autoload.php'; use Imagine\Image\Palette\Color\ColorInterface; use Imagine\Image\PointInterface; use Imagine\Image\ImageInterface; use Imagine\Image\Point; $topLeft = $bottomLeft = [99999, 0]; $topRight = $bottomRight = [0, 99999]; $gatherer = function (ColorInterface $color, PointInterface $point, ImageInterface $image) use (&$topLeft, &$topRight, &$bottomLeft, &$bottomRight) { if ($color->getAlpha() == 0) { return; } $x = $point->getX(); $y = $point->getY(); $top = $image->getColorAt(new Point($x, $y - 1))->isOpaque(); $bottom = $image->getColorAt(new Point($x, $y + 1))->isOpaque(); $left = $image->getColorAt(new Point($x - 1, $y))->isOpaque(); $right = $image->getColorAt(new Point($x + 1, $y))->isOpaque(); if (!$top && !$left && $bottom && $right && $x < $topLeft[0]) { $topLeft = [$x, $y]; } if (!$top && !$right && $bottom && $left && $x > $topRight[0]) { $topRight = [$x, $y]; } if (!$bottom && !$left && $top && $right && $x < $bottomLeft[0]) { $bottomLeft = [$x, $y]; } if (!$bottom && !$right && $top && $left && $x > $bottomRight[0]) { $bottomRight = [$x, $y]; } }; //$img = (new \Imagine\Gd\Imagine())->open(__DIR__ . '/numberplate-test.png'); $img = (new \Imagine\Gd\Imagine())->open(__DIR__ . '/numberplate-test2.png'); for ($top = 640; $top < 900; $top++) { for ($left = 340; $left < 1580; $left++) { $point = new Point($left, $top); $gatherer($img->getColorAt($point), $point, $img); } } var_dump($topLeft, $topRight, $bottomLeft, $bottomRight);
  11. It's missing a dollar sign. Use an IDE to point out the obvious errors.
  12. Ghehe I've been doing this for a long time now. Turning everything into an errorexception. Something along the lines of: set_error_handler(function($errno, $errstr, ..) { if ($errno === E_USER_DEPRECATED || $errno === E_DEPRECATED) { $this->notifier->sendDeprecatedMail($this->getApplicationInfo(), $errstr, ['file' => $errfile, 'line' => $errline, 'context' => $context]); return false; } if (!(error_reporting() & $errno)) { return false; } throw new ErrorException($errno, $errstr, ..); }); Didnt' knew about the password_hash() thing. Might need to revise
  13. $z_offset is undefined. Please turn on error_reporting like so: error_reporting(-1); ini_set('display_errors', 1); Also what is your date.timezone setting? echo date_default_timezone_get();
  14. Right off the bat, something like: for file in $(ls -A); do mv $file 'r'$file; done;
  15. No. That is a general class to send e-mails. I would create a specialised interface to send user related e-mails as demonstrated in my example. This way you can force the required parameters and decouple your code from knowing how to send these sort of e-mails otherwise you'd end up with code like: $to = $user->toEmail(); $subject = $this->translator->translate('Hello %name%', ['%name%' => $user->getFullName()]); $variables = [ // .. ]; $templateBody = $this->templateManager->getTemplateByName('user_registration'); $this->mailSubmissionAgent->send($to, $subject, $templateBody->resolve($variables), 'noreply@mydomain.com'); While this otherwise would be: $this->userMailer->sendWelcomeMail($user);
  16. public function register($to, $username, $password) { $raw_token = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); $encoded_token = bin2hex($raw_token); $token_hash = hash('sha256', $raw_token); $hashed_password = password_hash($password, PASSWORD_DEFAULT); try { $sql = ' INSERT INTO users (email, username, password, confirmation_key) VALUES (?, ?, ?, ?)'; $stmt = $this->database->prepare($sql); $stmt->execute([$to, $username, $hashed_password, $token_hash]); $subject = 'Confirm Email'; $body = "Click to activate account\r\n" . APPLICATION_URL . "/activate.php?k=$encoded_token"; $this->mailSubmissionAgent->send($to, $subject, $body, ADMIN_EMAIL_FROM); die(header("Location: ./login.php?confirm")); } catch(PDOException $e) { if ($e->getCode() == '23000') { $error[] = "Registration Failed"; $error[] = "Invalid Username or Email"; show_form_errors($error); } else { throw new Exception($e); } } // End Catch } You will probably have to create or update users in multiple places in your application so I would introduce a (interface) UserManager (=concrete PDOUserManager) to CRUD users. I would also create a separate class to send the registration e-mail perhaps one class to send all sort of user related e-mails. interface UserMailer extends MailSubmissionAgent { public function sendWelcomeMail(User $user); public function sendForgotPasswordMail($email); // you get the idea }
  17. Every registration is a user registration even when it's for a company. Or do your users register their company details but then don't bother creating a username and password?
  18. Here are 2 example interfaces. interface UserRegistration { public function __construct(UserManager $userManager, EventDispatcher $eventDispatcher); public function register(array $data): User; public function getErrors(): array; } interface UserManager { public function findByEmail($email): User; public function createUser(): User; public function updateUser(User $user): UserManager; public function deleteUser(User $user): UserManager; } The UserRegistration class would receive the data from the client, validate it, and throw an exception if it fails. The encountered errors can be retrieved with getErrors(). If the validation is successful, it creates the user through the UserManager, and insert the user with updateUser() (or addUser() if you prefer). This is the most basic form of a user registration and it should not handle more. Everything else would be handled through events: - Sending welcome e-mails, - Creating an invoice, - etc... Each of these event handlers may have their own interface as well.
  19. Sure a few of his examples are a little far-fetched. I have never had the trouble distinguishing between what a Translator is or what a TranslatorInterface does. I think SerializeToJson is a good descriptive name for the interface as would JsonSerializable I imagine. But again this is probably a bad example because an object should not be aware of what JSON is nor how it "serializes" itself to it. It gives you something to think about though the next time you develop a system. Proper naming is always half the battle. Even though I prefer to write an interface without the suffix on small (individual) and private projects, on big projects I tend to stick to "open-source" standards and that means *Interface suffix, *Trait suffix, and Abstract* prefix. This makes it easier to work together, and publish libraries.
  20. Is hardly a technical discussion.
  21. I used to use the *Interface suffix until I read this article: http://verraes.net/2013/09/sensible-interfaces/
  22. It doesn't know that's the entire point. someCodeThatCanDumpThings(VarDumper $dumper) The only thing that this function/method knows is that it can call $dumper with a method dump() which has certain arguments. The implementation details however it is unaware of. If this is to HTML or CLI or SOAP. It doesn't actually care. Through dependency injection you'll define what the implementation is going to be for the VarDumper interface.
  23. You can also pass the IP address as a constructor argument. Decoupling your class from the globals. If you use dependency injection it's even easier to do. Mind that when you are behind a proxy getting the IP address is not as simple as querying REMOTE_ADDR which further warrants the need for injection. class LoginAttemptsLog { /** * @var PDO the connection to the underlying database */ protected $database; /** * @var string */ protected $ipAddress; /** * @param PDO $database the connection to the underlying database * @param string $ipAddress the IP of the user */ public function __construct(PDO $database, $ipAddress) { $this->database = $database; $this->ipAddress = $ipAddress; } // .. }
  24. Kinda, it would be something like: class Quote { private $id; // .. other fields private $price; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; } // get*, set* for the other fields public function setPrice($price) { $this->price = $price; } public function getPrice() { return $this->price; } }Then you would create a query and populate this object: $sql = 'SELECT id, .., price FROM quotes'; $stmt = $this->db->prepare($sql); foreach ($stmt->fetchAll() as $row) { $quotes[] = $quote = new Quote; $quote->setId($row['id']); $quote->setPrice($row['price']); } return $quotes;At this point you can work with this object as: $quote->getId(); $quote->getPrice();Now before you start writing all of this yourself, there are frameworks available online that do this sort of thing for you. A list can be found here:https://github.com/ziadoz/awesome-php#database
×
×
  • 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.