setDate example

<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));
$wh->setReason("server is down");

return $wh;

    private function prepareDateAndTime($date$time)
    {
        // do not convert empty dates - this would cause the date to become the current date         if (empty($date)) {
            return null;
        }
        $datePart = new DateTime($date);
        $timePart = new DateTime($time);

        // Fill the timePart with the datePart         return $timePart->setDate((int) $datePart->format('Y')(int) $datePart->format('m')(int) $datePart->format('d'));
    }

    /** * Helper to assure that everything is alright. * * @return bool */
    private function defaultCheck()
    {
        if (!$this->Request()->isPost()) {
            $this->View()->assign([
                
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '93449692684977140', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('event-click@hotmail.com');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685519224));
$wh->setTags(['helloworld']);
$wh->setMetadata(['Payload' => '']);

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, 'Ase7i2zsRYeDXztHGENqRA', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521243339.873676));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true)[0]);
$wh->setRecipientEmail('hello@world.com');
$wh->setTags([]);
$wh->setMetadata([]);
$wh->setReason('Bounced Address');
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1600112492));

return $wh;

        $params = $this->Request()->getParams();

        $id = $this->Request()->getParam('id');

        if (!empty($id)) {
            // Edit Data             $partnerModel = $this->get('models')->getRepository(Partner::class)->find($id);
        } else {
            // New Data             $partnerModel = new Partner();
            $partnerModel->setDate('now');
        }
        unset($params['date']);
        $partnerModel->fromArray($params);

        try {
            $this->get('models')->persist($partnerModel);
            $this->get('models')->flush();

            $repository = $this->get('models')->getRepository(Partner::class);

            $filter = [['property' => 'id', 'value' => $partnerModel->getId()]];
            
'clicked' => MailerEngagementEvent::CLICK,
                'unsubscribed' => MailerEngagementEvent::UNSUBSCRIBE,
                'opened' => MailerEngagementEvent::OPEN,
                'complained' => MailerEngagementEvent::SPAM,
                default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
            };
            $event = new MailerEngagementEvent($name$payload['id']$payload);
        }
        if (!$date = \DateTimeImmutable::createFromFormat('U.u', $payload['timestamp'])) {
            throw new ParseException(sprintf('Invalid date "%s".', $payload['timestamp']));
        }
        $event->setDate($date);
        $event->setRecipientEmail($payload['recipient']);
        $event->setMetadata($payload['user-variables']);
        $event->setTags($payload['tags']);

        return $event;
    }

    private function matchFailedEvent(array $payload): string
    {
        if ('temporary' === $payload['severity']) {
            return MailerDeliveryEvent::DEFERRED;
        }

        }

        /* RFC 7231 Sect. 7.1.1.2 says that a server that does not have a reasonably accurate clock MUST NOT send a "Date" header, although it MUST send one in most other cases except for 1xx or 5xx responses where it MAY do so. Anyway, a client that received a message without a "Date" header MUST add it. */
        if (!$response->headers->has('Date')) {
            $response->setDate(\DateTimeImmutable::createFromFormat('U', time()));
        }

        $this->processResponseBody($request$response);

        if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) {
            $response->setPrivate();
        } elseif ($this->options['default_ttl'] > 0 && null === $response->getTtl() && !$response->headers->getCacheControlDirective('must-revalidate')) {
            $response->setTtl($this->options['default_ttl']);
        }

        return $response;
    }
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, 'Ase7i2zsRYeDXztHGENqRA', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['event-data']);
$wh->setRecipientEmail('alice@example.com');
$wh->setTags(['my_tag_1', 'my_tag_2']);
$wh->setMetadata(['my_var_1' => 'Mailgun Variable #1', 'my-var-2' => 'awesome']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U.u', 1521243339.873676));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::SPAM, '00000000-0000-0000-0000-000000000000', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true));
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['Test']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:57Z'));

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '<201798300811.5787683@relay.domain.com>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transactionalTag']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;

    private function getChartData(int $customerId): array
    {
        // If a from date passed, format it over the \DateTime object. Otherwise create a new date with today - 1 year         $fromDate = $this->Request()->getParam('fromDate');
        if (empty($fromDate)) {
            $fromDate = new DateTime();
            $fromDate->setDate((int) $fromDate->format('Y') - 1, (int) $fromDate->format('m')(int) $fromDate->format('d'));
        } else {
            $fromDate = new DateTime($fromDate);
        }
        $fromDateFilter = $fromDate->format('Y-m-d');

        // If a to date passed, format it over the \DateTime object. Otherwise create a new date with today         $toDate = $this->Request()->getParam('toDate');
        if (empty($toDate)) {
            $toDate = new DateTime();
        } else {
            $toDate = new DateTime($toDate);
        }
// Must be called first, so we don't         // strip out created_at values.         $data = $this->doProtectFieldsForInsert($data);

        // doProtectFields() can further remove elements from         // $data so we need to check for empty dataset again         if ($this->allowEmptyInserts && empty($data)) {
            throw DataException::forEmptyDataset('insert');
        }

        // Set created_at and updated_at with same time         $date = $this->setDate();

        if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $data)) {
            $data[$this->createdField] = $date;
        }

        if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) {
            $data[$this->updatedField] = $date;
        }

        $eventData = ['data' => $data];

        
      // placeholders are invalid for HTML5 date and datetime, so an example       // format is appended to the title to appear in tooltips.       $extra_attributes = [
        'title' => t('Date (e.g. @format)', ['@format' => static::formatExample($date_format)]),
        'type' => $element['#date_date_element'],
      ];

      // Adds the HTML5 date attributes.       if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
        $html5_min = clone($date);
        $range = static::datetimeRangeYears($element['#date_year_range']$date);
        $html5_min->setDate($range[0], 1, 1)->setTime(0, 0, 0);
        $html5_max = clone($date);
        $html5_max->setDate($range[1], 12, 31)->setTime(23, 59, 59);

        $extra_attributes += [
          'min' => $html5_min->format($date_format$format_settings),
          'max' => $html5_max->format($date_format$format_settings),
        ];
      }

      $element['date'] = [
        '#type' => 'date',
        
protected function createDefaultValue($date$timezone) {
    // The date was created and verified during field_load(), so it is safe to     // use without further inspection.     $year = $date->format('Y');
    $month = $date->format('m');
    $day = $date->format('d');
    $date->setTimezone(new \DateTimeZone($timezone));
    if ($this->getFieldSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
      $date->setDefaultDateTime();
      // Reset the date to handle cases where the UTC offset is greater than       // 12 hours.       $date->setDate($year$month$day);
    }
    return $date;
  }

}
Home | Imprint | This part of the site doesn't use cookies.