Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -12,6 +12,8 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\Response;
use Sly\NotificationPusher\Model\ResponseInterface;
/**
* AdapterInterface.
@@ -38,6 +40,16 @@ interface AdapterInterface
*/
public function supports($token);
/**
* @return ResponseInterface
*/
public function getResponse();
/**
* @param ResponseInterface $response
*/
public function setResponse(ResponseInterface $response);
/**
* Get defined parameters.
*
@@ -58,4 +70,20 @@ interface AdapterInterface
* @return array
*/
public function getRequiredParameters();
/**
* Get Environment.
*
* @return string
*/
public function getEnvironment();
/**
* Set Environment.
*
* @param string $environment Environment value to set
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
*/
public function setEnvironment($environment);
}

View File

@@ -11,20 +11,18 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Exception\AdapterException;
use Sly\NotificationPusher\Exception\PushException;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\PushInterface;
use ZendService\Apple\Apns\Client\AbstractClient as ServiceAbstractClient;
use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
use ZendService\Apple\Apns\Client\Message as ServiceClient;
use ZendService\Apple\Apns\Message as ServiceMessage;
use ZendService\Apple\Apns\Message\Alert as ServiceAlert;
use ZendService\Apple\Apns\Response\Message as ServiceResponse;
use ZendService\Apple\Apns\Exception\RuntimeException as ServiceRuntimeException;
use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
/**
* APNS adapter.
@@ -33,13 +31,17 @@ use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Apns extends BaseAdapter
class Apns extends BaseAdapter implements FeedbackAdapterInterface
{
/** @var ServiceClient */
/**
* @var ServiceClient
*/
private $openedClient;
/** @var ServiceFeedbackClient */
/**
* @var ServiceFeedbackClient
*/
private $feedbackClient;
/**
@@ -70,16 +72,32 @@ class Apns extends BaseAdapter
$pushedDevices = new DeviceCollection();
foreach ($push->getDevices() as $device) {
/** @var \ZendService\Apple\Apns\Message $message */
$message = $this->getServiceMessageFromOrigin($device, $push->getMessage());
try {
$this->response = $client->send($message);
} catch (ServiceRuntimeException $e) {
throw new PushException($e->getMessage());
}
/** @var \ZendService\Apple\Apns\Response\Message $response */
$response = $client->send($message);
if (ServiceResponse::RESULT_OK === $this->response->getCode()) {
$pushedDevices->add($device);
$responseArr = [
'id' => $response->getId(),
'token' => $response->getCode(),
];
$push->addResponse($device, $responseArr);
if (ServiceResponse::RESULT_OK === $response->getCode()) {
$pushedDevices->add($device);
} else {
$client->close();
unset($this->openedClient, $client);
// Assign returned new client to the in-scope/in-use $client variable
$client = $this->getOpenedServiceClient();
}
$this->response->addOriginalResponse($device, $response);
$this->response->addParsedResponse($device, $responseArr);
} catch (\RuntimeException $e) {
throw new PushException($e->getMessage());
}
}
@@ -97,6 +115,7 @@ class Apns extends BaseAdapter
$responses = [];
$serviceResponses = $client->feedback();
/** @var \ZendService\Apple\Apns\Response\Feedback $response */
foreach ($serviceResponses as $response) {
$responses[$response->getToken()] = new \DateTime(date('c', $response->getTime()));
}
@@ -107,12 +126,16 @@ class Apns extends BaseAdapter
/**
* Get opened client.
*
* @param \ZendService\Apple\Apns\Client\AbstractClient $client Client
* @param \ZendService\Apple\Apns\Client\AbstractClient|null $client Client
*
* @return \ZendService\Apple\Apns\Client\AbstractClient
*/
public function getOpenedClient(ServiceAbstractClient $client)
public function getOpenedClient(ServiceAbstractClient $client = null)
{
if (!$client) {
$client = new ServiceClient();
}
$client->open(
$this->isProductionEnvironment() ? ServiceClient::PRODUCTION_URI : ServiceClient::SANDBOX_URI,
$this->getParameter('certificate'),
@@ -125,9 +148,9 @@ class Apns extends BaseAdapter
/**
* Get opened ServiceClient
*
* @return ServiceAbstractClient
* @return ServiceClient
*/
private function getOpenedServiceClient()
protected function getOpenedServiceClient()
{
if (!isset($this->openedClient)) {
$this->openedClient = $this->getOpenedClient(new ServiceClient());
@@ -139,7 +162,7 @@ class Apns extends BaseAdapter
/**
* Get opened ServiceFeedbackClient
*
* @return ServiceAbstractClient
* @return ServiceFeedbackClient
*/
private function getOpenedFeedbackClient()
{
@@ -161,13 +184,14 @@ class Apns extends BaseAdapter
public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
{
$badge = ($message->hasOption('badge'))
? (int) ($message->getOption('badge') + $device->getParameter('badge', 0))
: false
;
? (int)($message->getOption('badge') + $device->getParameter('badge', 0))
: false;
$sound = $message->getOption('sound', 'bingbong.aiff');
$sound = $message->getOption('sound');
$contentAvailable = $message->getOption('content-available');
$category = $message->getOption('category');
$category = $message->getOption('category');
$urlArgs = $message->getOption('urlArgs');
$expire = $message->getOption('expire');
$alert = new ServiceAlert(
$message->getText(),
@@ -202,7 +226,7 @@ class Apns extends BaseAdapter
}
$serviceMessage = new ServiceMessage();
$serviceMessage->setId(sha1($device->getToken().$message->getText()));
$serviceMessage->setId(sha1($device->getToken() . $message->getText()));
$serviceMessage->setAlert($alert);
$serviceMessage->setToken($device->getToken());
if (false !== $badge) {
@@ -222,6 +246,14 @@ class Apns extends BaseAdapter
$serviceMessage->setCategory($category);
}
if (null !== $urlArgs) {
$serviceMessage->setUrlArgs($urlArgs);
}
if (null !== $expire) {
$serviceMessage->setExpire($expire);
}
return $serviceMessage;
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* Created by PhpStorm.
* User: seyfer
* Date: 09.08.17
* Time: 17:03
*/
namespace Sly\Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Adapter\BaseAdapter;
use Sly\NotificationPusher\Model\PushInterface;
/**
* Class ApnsAPI
* @package Sly\Sly\NotificationPusher\Adapter
*
* todo: implement with edamov/pushok
*/
class ApnsAPI extends BaseAdapter
{
/**
* Push.
*
* @param \Sly\NotificationPusher\Model\PushInterface $push Push
*
* @return \Sly\NotificationPusher\Collection\DeviceCollection
*/
public function push(PushInterface $push)
{
// TODO: Implement push() method.
}
/**
* Supports.
*
* @param string $token Token
*
* @return boolean
*/
public function supports($token)
{
// TODO: Implement supports() method.
}
/**
* Get defined parameters.
*
* @return array
*/
public function getDefinedParameters()
{
// TODO: Implement getDefinedParameters() method.
}
/**
* Get default parameters.
*
* @return array
*/
public function getDefaultParameters()
{
// TODO: Implement getDefaultParameters() method.
}
/**
* Get required parameters.
*
* @return array
*/
public function getRequiredParameters()
{
// TODO: Implement getRequiredParameters() method.
}
}

View File

@@ -11,10 +11,11 @@
namespace Sly\NotificationPusher\Adapter;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Sly\NotificationPusher\Model\BaseParameteredModel;
use Sly\NotificationPusher\Model\Response;
use Sly\NotificationPusher\Model\ResponseInterface;
use Sly\NotificationPusher\PushManager;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* BaseAdapter.
@@ -34,7 +35,7 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
protected $environment;
/**
* @var mixed
* @var ResponseInterface
*/
protected $response;
@@ -53,6 +54,23 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
$reflectedClass = new \ReflectionClass($this);
$this->adapterKey = lcfirst($reflectedClass->getShortName());
$this->parameters = $resolver->resolve($parameters);
$this->response = new Response();
}
/**
* @return ResponseInterface
*/
public function getResponse()
{
return $this->response;
}
/**
* @param ResponseInterface $response
*/
public function setResponse(ResponseInterface $response)
{
$this->response = $response;
}
/**
@@ -65,16 +83,6 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
return ucfirst($this->getAdapterKey());
}
/**
* Return the original response.
*
* @return mixed
*/
public function getResponse()
{
return $this->response;
}
/**
* Get AdapterKey.
*
@@ -128,4 +136,5 @@ abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterf
{
return (PushManager::ENVIRONMENT_PROD === $this->getEnvironment());
}
}

View File

@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: seyfer
* Date: 09.08.17
* Time: 16:06
*/
namespace Sly\NotificationPusher\Adapter;
interface FeedbackAdapterInterface
{
public function getFeedback();
}

View File

@@ -11,19 +11,18 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\PushInterface;
use InvalidArgumentException;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Exception\PushException;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\GcmMessage;
use Sly\NotificationPusher\Model\PushInterface;
use Zend\Http\Client as HttpClient;
use Zend\Http\Client\Adapter\Socket as HttpSocketAdapter;
use ZendService\Google\Exception\RuntimeException as ServiceRuntimeException;
use ZendService\Google\Gcm\Client as ServiceClient;
use ZendService\Google\Gcm\Message as ServiceMessage;
use ZendService\Google\Exception\RuntimeException as ServiceRuntimeException;
use InvalidArgumentException;
/**
* GCM adapter.
@@ -49,7 +48,7 @@ class Gcm extends BaseAdapter
*/
public function supports($token)
{
return is_string($token) && $token != '';
return is_string($token) && $token !== '';
}
/**
@@ -67,16 +66,40 @@ class Gcm extends BaseAdapter
$message = $this->getServiceMessageFromOrigin($tokensRange, $push->getMessage());
try {
$this->response = $client->send($message);
/** @var \ZendService\Google\Gcm\Response $response */
$response = $client->send($message);
$responseResults = $response->getResults();
foreach ($tokensRange as $token) {
/** @var DeviceInterface $device */
$device = $push->getDevices()->get($token);
// map the overall response object
// into a per device response
$tokenResponse = [];
if (isset($responseResults[$token]) && is_array($responseResults[$token])) {
$tokenResponse = $responseResults[$token];
}
$responseData = $response->getResponse();
if ($responseData && is_array($responseData)) {
$tokenResponse = array_merge(
$tokenResponse,
array_diff_key($responseData, ['results' => true])
);
}
$push->addResponse($device, $tokenResponse);
$pushedDevices->add($device);
$this->response->addOriginalResponse($device, $response);
$this->response->addParsedResponse($device, $tokenResponse);
}
} catch (ServiceRuntimeException $e) {
throw new PushException($e->getMessage());
}
if ((bool) $this->response->getSuccessCount()) {
foreach ($tokensRange as $token) {
$pushedDevices->add($push->getDevices()->get($token));
}
}
}
return $pushedDevices;
@@ -96,8 +119,8 @@ class Gcm extends BaseAdapter
$newClient = new \Zend\Http\Client(
null,
[
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'sslverifypeer' => false
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'sslverifypeer' => false,
]
);
@@ -114,6 +137,7 @@ class Gcm extends BaseAdapter
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \ZendService\Google\Gcm\Message
* @throws \ZendService\Google\Exception\InvalidArgumentException
*/
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
{
@@ -122,7 +146,18 @@ class Gcm extends BaseAdapter
$serviceMessage = new ServiceMessage();
$serviceMessage->setRegistrationIds($tokens);
if (isset($data['notificationData']) && !empty($data['notificationData'])) {
$serviceMessage->setNotification($data['notificationData']);
unset($data['notificationData']);
}
if ($message instanceof GcmMessage) {
$serviceMessage->setNotification($message->getNotificationData());
}
$serviceMessage->setData($data);
$serviceMessage->setCollapseKey($this->getParameter('collapseKey'));
$serviceMessage->setRestrictedPackageName($this->getParameter('restrictedPackageName'));
$serviceMessage->setDelayWhileIdle($this->getParameter('delayWhileIdle', false));
@@ -138,11 +173,11 @@ class Gcm extends BaseAdapter
public function getDefinedParameters()
{
return [
'collapse_key',
'delay_while_idle',
'time_to_live',
'restricted_package_name',
'dry_run'
'collapseKey',
'delayWhileIdle',
'ttl',
'restrictedPackageName',
'dryRun',
];
}