/** * {@inheritDoc} */ public function transform(AttributeEvent $event) { $value = $event->getValue(); if (strtolower($value) == 'transform and roll out') { $event->setValue($this->getQuote()); } }
/** * {@inheritDoc} * * @throws \UnexpectedValueException */ public function render(AttributeEvent $event) { $data = base64_decode($event->getValue()); if (false === $data) { throw new \UnexpectedValueException('Error decoding data in the ' . $event->getAttribute() . ' attribute'); } $event->setValue($data); }
/** * {@inheritDoc} */ public function transform(AttributeEvent $event) { $value = $event->getValue(); if (preg_match(self::REGEX, $value, $matches)) { $length = isset($matches[1]) ? $matches[1] : $this->defaultLength; $event->setValue($this->generateRandomString($length)); } }
/** * {@inheritDoc} */ public function render(AttributeEvent $event) { $dateString = $event->getValue(); if (ctype_digit($dateString)) { $dateString = '@' . $dateString; } $time = new \DateTime($dateString); if (isset($this->timezone)) { $time->setTimezone($this->timezone); } $event->setValue($time); }
/** * {@inheritDoc} * * @throws \InvalidArgumentException */ public function transform(AttributeEvent $event) { $value = $event->getValue(); if ($value instanceof \DateTime) { $timestamp = $value->getTimestamp(); } elseif (is_int($value)) { $timestamp = $value; } else { $timestamp = strtotime($value); if ($timestamp === false) { throw new \InvalidArgumentException('Expecting value to be an instance of \\DateTime, a Unix timestamp, ot a textual datetime description'); } } $event->setValue($timestamp); }
/** * {@inheritDoc} * * @throws \UnexpectedValueException */ public function render(AttributeEvent $event) { $cipherText = $event->getValue(); // The Amazon SDK base64 encodes binary strings before it sends data to // DynamoDB, but it does not base64 decode it after it retrieves the // data from DynamoDB. Therefore we have to check wheter it is encoded. if (preg_match(self::BASE64_REGEX, $cipherText)) { $cipherText = base64_decode($cipherText); if (false === $cipherText) { throw new \UnexpectedValueException('Error decoding data in the ' . $event->getAttribute() . ' attribute'); } } $plainText = $this->cipher->decrypt($cipherText); if (false === $plainText) { throw new \UnexpectedValueException('Error decrypting data in the ' . $event->getAttribute() . ' attribute: Invalid key'); } $event->setValue($plainText); }
/** * {@inheritDoc} */ public function transform(AttributeEvent $event) { $plainText = $event->getValue(); $hash = password_hash($plainText, $this->algo, array('cost' => $this->cost)); $event->setValue($hash); }
/** * {@inheritDoc} */ public function transform(AttributeEvent $event) { $value = $event->getValue(); $event->setValue($this->cipher->encrypt($value)); }
/** * {@inheritDoc} * * @throws \InvalidArgumentException */ public function transform(AttributeEvent $event) { $json = json_encode($event->getValue(), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT); $event->setValue($json); }
/** * {@inheritDoc} */ public function render(AttributeEvent $event) { $data = json_decode($event->getValue(), true); $event->setValue($data); }