seeder-migration-issues

This commit is contained in:
RafficMohammed
2023-01-30 14:23:34 +05:30
parent 4d918c722f
commit 2ec836b447
3628 changed files with 116006 additions and 187 deletions

View File

@@ -0,0 +1,89 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* BaseOptionedModel.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseOptionedModel
{
/**
* @var array
*/
protected $options = array();
/**
* Get options.
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* Has option.
*
* @param string $key Key
*
* @return boolean
*/
public function hasOption($key)
{
return array_key_exists($key, $this->options);
}
/**
* Get option.
*
* @param string $key Key
* @param mixed $default Default
*
* @return mixed
*/
public function getOption($key, $default = null)
{
return $this->hasOption($key) ? $this->options[$key] : $default;
}
/**
* Set options.
*
* @param array $options Options
*
* @return \Sly\NotificationPusher\Model\BaseOptionedModel
*/
public function setOptions($options)
{
$this->options = $options;
return $this;
}
/**
* Set option.
*
* @param string $key Key
* @param mixed $value Value
*
* @return mixed
*/
public function setOption($key, $value)
{
$this->options[$key] = $value;
return $value;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* BaseParameteredModel.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseParameteredModel
{
/**
* @var array
*/
protected $parameters = array();
/**
* Get parameters.
*
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* Has parameter.
*
* @param string $key Key
*
* @return boolean
*/
public function hasParameter($key)
{
return array_key_exists($key, $this->parameters);
}
/**
* Get parameter.
*
* @param string $key Key
* @param mixed $default Default
*
* @return mixed
*/
public function getParameter($key, $default = null)
{
return $this->hasParameter($key) ? $this->parameters[$key] : $default;
}
/**
* Set parameters.
*
* @param array $parameters Parameters
*
* @return \Sly\NotificationPusher\Model\BaseParameteredModel
*/
public function setParameters($parameters)
{
$this->parameters = $parameters;
return $this;
}
/**
* Set parameter.
*
* @param string $key Key
* @param mixed $value Value
*
* @return mixed
*/
public function setParameter($key, $value)
{
$this->parameters[$key] = $value;
return $value;
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* Device.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Device extends BaseParameteredModel implements DeviceInterface
{
/**
* @var string
*/
private $token;
/**
* Constructor.
*
* @param string $token Token
* @param array $parameters Parameters
*/
public function __construct($token, array $parameters = array())
{
$this->token = $token;
$this->parameters = $parameters;
}
/**
* Get token.
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Set token.
*
* @param string $token Token
*
* @return \Sly\NotificationPusher\Model\DeviceInterface
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* DeviceInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface DeviceInterface
{
/**
* Get token.
*
* @return string
*/
public function getToken();
/**
* Set token.
*
* @param string $token Token
*
* @return \Sly\NotificationPusher\Model\DeviceInterface
*/
public function setToken($token);
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* Message.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Message extends BaseOptionedModel implements MessageInterface
{
/**
* @var string
*/
private $text;
/**
* Constructor.
*
* @param string $text Text
* @param array $options Options
*/
public function __construct($text, array $options = array())
{
$this->text = $text;
$this->options = $options;
}
/**
* Get Text.
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Set Text.
*
* @param string $text Text
*
* @return \Sly\NotificationPusher\Model\MessageInterface
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
/**
* MessageInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
interface MessageInterface
{
/**
* Get Text.
*
* @return string
*/
public function getText();
/**
* Set Text.
*
* @param string $text Text
*
* @return \Sly\NotificationPusher\Model\MessageInterface
*/
public function setText($text);
}

View File

@@ -0,0 +1,246 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Exception\AdapterException;
/**
* Push.
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Push extends BaseOptionedModel implements PushInterface
{
/**
* @var string
*/
private $status;
/**
* @var \Sly\NotificationPusher\Adapter\AdapterInterface
*/
private $adapter;
/**
* @var \Sly\NotificationPusher\Model\MessageInterface
*/
private $message;
/**
* @var \Sly\NotificationPusher\Collection\DeviceCollection
*/
private $devices;
/**
* @var \DateTime
*/
private $pushedAt;
/**
* Constructor.
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
* @param DeviceInterface|DeviceCollection $devices Device(s)
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param array $options Options
*
* Options are adapters specific ones, like Apns "badge" or "sound" option for example.
* Of course, they can be more general.
*
* @throws \Sly\NotificationPusher\Exception\AdapterException
*/
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = array())
{
if ($devices instanceof DeviceInterface) {
$devices = new DeviceCollection(array($devices));
}
$this->adapter = $adapter;
$this->devices = $devices;
$this->message = $message;
$this->options = $options;
$this->status = self::STATUS_PENDING;
$this->checkDevicesTokens();
}
/**
* Check devices tokens.
*/
private function checkDevicesTokens()
{
$devices = $this->getDevices();
$adapter = $this->getAdapter();
foreach ($devices as $device) {
if (false === $adapter->supports($device->getToken())) {
throw new AdapterException(
sprintf(
'Adapter %s does not supports %s token\'s device',
(string) $adapter,
$device->getToken()
)
);
}
}
}
/**
* Get Status.
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Set Status.
*
* @param string $status Status
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* isPushed.
*
* @return boolean
*/
public function isPushed()
{
return (bool) (self::STATUS_PUSHED === $this->status);
}
/**
* Declare as pushed.
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function pushed()
{
$this->status = self::STATUS_PUSHED;
$this->pushedAt = new \DateTime();
return $this;
}
/**
* Get Adapter.
*
* @return \Sly\NotificationPusher\Adapter\AdapterInterface
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* Set Adapter.
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* Get Message.
*
* @return \Sly\NotificationPusher\Model\MessageInterface
*/
public function getMessage()
{
return $this->message;
}
/**
* Set Message.
*
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function setMessage(MessageInterface $message)
{
$this->message = $message;
return $this;
}
/**
* Get Devices.
*
* @return \Sly\NotificationPusher\Collection\DeviceCollection
*/
public function getDevices()
{
return $this->devices;
}
/**
* Set Devices.
*
* @param \Sly\NotificationPusher\Collection\DeviceCollection $devices Devices
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function setDevices(DeviceCollection $devices)
{
$this->devices = $devices;
$this->checkDevicesTokens();
return $this;
}
/**
* Get PushedAt.
*
* @return \DateTime
*/
public function getPushedAt()
{
return $this->pushedAt;
}
/**
* Set PushedAt.
*
* @param \DateTime $pushedAt PushedAt
*
* @return \Sly\NotificationPusher\Model\PushInterface
*/
public function setPushedAt(\DateTime $pushedAt)
{
$this->pushedAt = $pushedAt;
return $this;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/*
* This file is part of NotificationPusher.
*
* (c) 2013 Cédric Dugat <cedric@dugat.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sly\NotificationPusher\Model;
use DateTime;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
/**
* PushInterface
*/
interface PushInterface
{
/**
* Constants define available statuses
*/
const STATUS_PENDING = 'pending';
const STATUS_PUSHED = 'sent';
/**
* Get Status.
*
* @return string
*/
public function getStatus();
/**
* Set Status.
*
* @param string $status Status
*
* @return PushInterface
*/
public function setStatus($status);
/**
* isPushed.
*
* @return boolean
*/
public function isPushed();
/**
* Declare as pushed.
*
* @return PushInterface
*/
public function pushed();
/**
* Get Adapter.
*
* @return AdapterInterface
*/
public function getAdapter();
/**
* Set Adapter.
*
* @param AdapterInterface $adapter Adapter
*
* @return PushInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Get Message.
*
* @return MessageInterface
*/
public function getMessage();
/**
* Set Message.
*
* @param MessageInterface $message Message
*
* @return PushInterface
*/
public function setMessage(MessageInterface $message);
/**
* Get Devices.
*
* @return DeviceCollection
*/
public function getDevices();
/**
* Set Devices.
*
* @param DeviceCollection $devices Devices
*
* @return PushInterface
*/
public function setDevices(DeviceCollection $devices);
/**
* Get PushedAt.
*
* @return DateTime
*/
public function getPushedAt();
/**
* Set PushedAt.
*
* @param DateTime $pushedAt PushedAt
*
* @return PushInterface
*/
public function setPushedAt(DateTime $pushedAt);
}