@param Notification $notification
@param array        $params

@return Notification
340123
protected function prepareNotification(Notification $notification, $params = array())
    {
        $data = array_filter($notification->toArray());
        // Prevent from duplicating context items
        unset($data['context']);

        $params += array('origin' => php_sapi_name() == 'cli' ? 'cli' : 'http');
        $params += array('reported_at' => new \DateTime());
        $params += array('server' => $this->getServerName());

        $mergedData = array_merge($data, $params);

        $notification->hydrate($mergedData);

        return $notification;
    }
101208
public static function sendNotification(Notification $notification, $content = null)
    {
        $beforeSendCallback = $notification->beforeSendCallback();
        self::_performCallback($beforeSendCallback, $notification);

        if ($notification->locale() !== null) {
            I18n::locale($notification->locale());
        } else {
            I18n::locale(Configure::read('Notifications.defaultLocale'));
        }

        $notification->email()->send($content);

        $afterSendCallback = $notification->afterSendCallback();
        self::_performCallback($afterSendCallback);

        return $notification;
    }
139315
public static function make($notifiable, Notification $notification, $targeting): array
    {
        $payload = $notification->toOneSignal($notifiable)->toArray();

        if (static::isTargetingEmail($targeting)) {
            $payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]);
        } elseif (static::isTargetingTags($targeting)) {
            $array = $targeting['tags'];
            $res = count($array) == count($array, COUNT_RECURSIVE);
            if ($res) {
                $payload['tags'] = collect([$targeting['tags']]);
            } else {
                $payload['tags'] = collect($targeting['tags']);
            }
        } elseif (static::isTargetingIncludedSegments($targeting)) {
            $payload['included_segments'] = collect($targeting['included_segments']);
        } elseif (static::isTargetingExcludedSegments($targeting)) {
            $payload['excluded_segments'] = collect($targeting['excluded_segments']);
        } elseif (static::isTargetingExternalUserIds($targeting)) {
            $payload['include_external_user_ids'] = collect($targeting['include_external_user_ids']);
        } else {
            $payload['include_player_ids'] = collect($targeting);
        }

        return $payload;
    }
373027
public function notify(NotificationInterface $notification)
    {
        $notified = false;
        $this->eventDispatcher->dispatch(Events::PRE_NOTIFY, new PreNotifyEvent($notification));

        foreach ($this->handlers as $handler) {
            if ($notification->getHandlerName() !== $handler->getName()) {
                continue;
            }
            $notified = $this->handle($notification, $handler) || $notified;
        }

        if ($this->throwIfNotNotified && ! $notified) {
            $message = 'No handler has been defined for '.\get_class($notification);
            if (\method_exists($notification, 'getConfig')) {
                $message .= ' ('.\json_encode($notification->getConfig()).')';
            }

            throw new NotificationFailedException($message);
        }

        $this->eventDispatcher->dispatch(Events::POST_NOTIFY, new PostNotifyEvent($notification));
    }
671371
public function sendNow($notifiables, $notification, array $channels = null)
    {
        $notifiables = $this->formatNotifiables($notifiables);

        $original = clone $notification;

        foreach ($notifiables as $notifiable) {
            if (empty($viaChannels = $channels ?: $notification->via($notifiable))) {
                continue;
            }

            $notificationId = Uuid::uuid4()->toString();

            foreach ((array) $viaChannels as $channel) {
                $this->sendToNotifiable($notifiable, $notificationId, clone $original, $channel);
            }
        }
    }
631511
protected function toCollect($notification) : Collection
    {
        return Collection::make([
            'hasBeenRead' => ! is_null($notification->read_at),
            'path' => $notification->data['source_path'],
            'label' => $notification->data['label'],
            'id' => $notification->id,
        ]);
    }
267997
private function addPadding(string $notification) : string
    {
        $length = $this->length;

        return pack('n*', $length).str_pad($notification, $length + 2, chr(0), STR_PAD_LEFT);
    }
501938
protected function getData($notifiable, Notification $notification)
    {
        if (method_exists($notification, 'toBroadcast')) {
            return $notification->toBroadcast($notifiable);
        }

        if (method_exists($notification, 'toArray')) {
            return $notification->toArray($notifiable);
        }

        throw new RuntimeException('Notification is missing toArray method.');
    }
1218054
public function post(Notification $notification)
    {
        $notificationApi = $this->doPost('/post', $notification->toArray());

        if (200 !== $notificationApi->getResponse()->getStatusCode()
            && 201 !== $notificationApi->getResponse()->getStatusCode()) {
            throw new ApiException('cannot send notification', $this->getRequest(), $this->getResponse());
        }

        return true;
    }
1096841
public function sendNotifications($notification_type, array $args = [])
    {
        if (!isset($this->_notifications[$notification_type])) {
            // No exception thrown and error logged since this method will be called from
            // within the SDK
            return;
        }

        /**
         * Note: Before PHP 7, if the callback in call_user_func is called with less number of arguments than expected,
         * a warning is issued but the method is still executed with assigning null to the remaining
         * arguments. From PHP 7, ArgumentCountError is thrown in such case and the method isn't executed.
         * Therefore, we set error handler for warnings so that we raise an exception and notify the
         * user that the registered callback has more number of arguments than
         * expected. This should be done to keep a consistent behavior across all PHP versions.
         */

        set_error_handler(array($this, 'reportArgumentCountError'), E_WARNING);

        foreach (array_values($this->_notifications[$notification_type]) as $callback) {
            try {
                call_user_func_array($callback, $args);
            } catch (ArgumentCountError $e) {
                $this->reportArgumentCountError();
            } catch (Exception $e) {
                $this->_logger->log(Logger::ERROR, "Problem calling notify callback.");
            }
        }

        restore_error_handler();
    }
54929
protected function buildMessage($notifiable, Notification $notification)
    {
        $message = call_user_func_array([$notification, $this->getToMethod()], [$notifiable]);

        if (is_string($message)) {
            $message = new PushMessage($message);
        }

        return $message;
    }
568439
private static function get_notification_details( $notification ) {
		$notifications = array_filter(
			self::$notifications,
			function ( $value ) use ( $notification ) {
				if ( isset( $value['id'] ) && isset( $notification['id'] ) && $value['id'] === $notification['id'] ) {
					return true;
				}

				return false;
			}
		);

		return ! empty( $notifications ) ? reset( $notifications ) : [];
	}
1074991
public function push(array $tokens = [], array $notifications = [], array $params = [])
    {
        if (!$tokens || !$notifications) {
            return null;
        }

        $adapterParams = [];
        $deviceParams  = [];
        $messageParams = [];
        if (isset($params) && !empty($params)) {
            if (isset($params['adapter'])) {
                $adapterParams = $params['adapter'];
            }

            if (isset($params['device'])) {
                $deviceParams = $params['device'];
            }

            if (isset($params['message'])) {
                $messageParams = $params['message'];
            }

            //because we have now notification and data separated
            if (isset($params['notificationData'])) {
                $messageParams['notificationData'] = $params['notificationData'];
            }
        }

        $adapterParams['apiKey'] = $this->apiKey;

        if (!$this->apiKey) {
            throw new \RuntimeException('Android api key must be set');
        }

        // Development one by default (without argument).
        /** @var PushManager $pushManager */
        $pushManager = new PushManager($this->environment);

        // Then declare an adapter.
        $gcmAdapter = new GcmAdapter($adapterParams);

        // Set the device(s) to push the notification to.
        $devices = new DeviceCollection([]);

        //devices
        foreach ($tokens as $token) {
            $devices->add(new Device($token, $deviceParams));
        }

        foreach ($notifications as $notificationText) {
            // Then, create the push skel.
            $message = new Message($notificationText, $messageParams);

            // Finally, create and add the push to the manager, and push it!
            $push = new Push($gcmAdapter, $devices, $message);
            $pushManager->add($push);
        }

        // Returns a collection of notified devices
        $pushes = $pushManager->push();

        $this->response = $gcmAdapter->getResponse();

        return $this->response;
    }
504345
protected function registerNotification(array $notification)
    {
        $view = $this->getView();

        $options = Json::encode(ArrayHelper::merge($this->getClientOptions(), $notification));
        $view->registerJs("new PNotify({$options});");
    }
560266
public function send($id, $notification) {
		$pushEntity = $this->prepareSend($notification);
		$fireUser = \App::$domain->account->fireUser->oneById($id);
		$fireBase = new FireBaseSend();
		return $fireBase->send('dYxtWvqaR1A:APA91bEIhkotwlCtW0ld-7A22U3bMM5kMI4MPd8lahQkmo95hpO_zukxDrKY9fwcYutud5DufyeE-g-9L9BoWycXJC1CravdFNR-wTUnYjvTyAtuJBKOmL4vgd2LD1FIGUtbuCwiokaR'
			, $pushEntity->toArray());
	}
615272
public function setRPCNotification($notification)
    {
        empty($notification) ? $this->notification = false : $this->notification = true;
    }
798100
public function sendNotification($notification)
    {
        $subscriberIds = $notification->subscriberIds->toArray();
        $query = $this->getService('repos:people.person')
                       ->getQuery(true)
                       ->id($subscriberIds);

        $people = $query->fetchSet();

        $settings = $this->getService('repos:notifications.setting')
                         ->getQuery(true, array('actor.id' => $notification->target->id))
                         ->fetchSet();

        $settings = AnHelperArray::indexBy($settings, 'person.id');

        $mails = $this->_renderMails(array(
                        'notification' => $notification,
                        'people' => $people,
                        'settings' => $settings
                    ));

        $this->mail($mails);
    }