Skip to content

Commit

Permalink
Merge pull request #32 from ancarebeca/issue-27
Browse files Browse the repository at this point in the history
Issue 27
  • Loading branch information
ancarebeca authored Mar 29, 2017
2 parents 75e7c5a + 864f8e9 commit ffdd71c
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
/vendor/
composer.lock
gi
.DS_Store
7 changes: 4 additions & 3 deletions Event/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AncaRebeca\FullCalendarBundle\Event;

use AncaRebeca\FullCalendarBundle\Model\EventInterface;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;
use Symfony\Component\EventDispatcher\Event as EventDispatcher;

class CalendarEvent extends EventDispatcher
Expand Down Expand Up @@ -66,11 +67,11 @@ public function getFilters()
}

/**
* @param EventInterface $event
* @param FullCalendarEvent $event
*
* @return $this
*/
public function addEvent(EventInterface $event)
public function addEvent(FullCalendarEvent $event)
{
if (!in_array($event, $this->events, true)) {
$this->events[] = $event;
Expand All @@ -80,7 +81,7 @@ public function addEvent(EventInterface $event)
}

/**
* @return EventInterface[]
* @return FullCalendarEvent[]
*/
public function getEvents()
{
Expand Down
6 changes: 6 additions & 0 deletions Model/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace AncaRebeca\FullCalendarBundle\Model;

/**
* Interface EventInterface
* @deprecated since version V4.1.0, to be removed in v5.0.0. Use FullCalendarEvent instead
*
*/
interface EventInterface
{
/**
* @param string $title
* @param \DateTime $start
*
*/
public function __construct($title, \DateTime $start);

Expand Down
31 changes: 31 additions & 0 deletions Model/FullCalendarEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace AncaRebeca\FullCalendarBundle\Model;

abstract class FullCalendarEvent
{
/**
* @var string
*/
protected $title;

/**
* @var \DateTime
*/
protected $startDate;

/**
* @param string $title
* @param \DateTime $start
*/
public function __construct($title, \DateTime $start)
{
$this->title = $title;
$this->startDate = $start;
}

/**
* @return array
*/
abstract public function toArray();
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function registerBundles()

namespace AppBundle\Entity;

use AncaRebeca\FullCalendarBundle\Model\Event as BaseEvent;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;

class CalendarEvent extends BaseEvent
class CalendarEvent extends FullCalendarEvent
{
// Your fields
}
Expand Down Expand Up @@ -79,15 +79,15 @@ This listener is called when the event 'fullcalendar.set_data' is launched, for

namespace AppBundle\Listener;

use AncaRebeca\FullCalendarBundle\Event\CalendarEvent;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;
use AppBundle\Entity\CalendarEvent as MyCustomEvent;

class LoadDataListener
{
/**
* @param CalendarEvent $calendarEvent
*
* @return EventInterface[]
* @return FullCalendarEvent[]
*/
public function loadData(CalendarEvent $calendarEvent)
{
Expand Down
5 changes: 2 additions & 3 deletions Service/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

namespace AncaRebeca\FullCalendarBundle\Service;

use AncaRebeca\FullCalendarBundle\Model\EventInterface;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;

class Serializer implements SerializerInterface
{
/**
* @param EventInterface[] $events
* @param FullCalendarEvent[] $events
*
* @return string json
*/
public function serialize(array $events)
{
$result = [];

/** @var EventInterface $event */
foreach ($events as $event) {
$result[] = $event->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions Service/SerializerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace AncaRebeca\FullCalendarBundle\Service;

use AncaRebeca\FullCalendarBundle\Model\EventInterface;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;

interface SerializerInterface
{
/**
* @param EventInterface[] $events
* @param FullCalendarEvent[] $events
*
* @return string json
*/
Expand Down
4 changes: 0 additions & 4 deletions spec/Model/EventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ function it_is_initializable()
$this->shouldHaveType('AncaRebeca\FullCalendarBundle\Model\Event');
}

function it_should_implement_an_event_interface()
{
$this->shouldImplement('AncaRebeca\FullCalendarBundle\Model\EventInterface');
}

function it_has_require_values()
{
Expand Down
4 changes: 2 additions & 2 deletions spec/Service/CalendarSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace spec\AncaRebeca\FullCalendarBundle\Service;

use AncaRebeca\FullCalendarBundle\Event\CalendarEvent;
use AncaRebeca\FullCalendarBundle\Model\EventInterface;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;
use AncaRebeca\FullCalendarBundle\Service\SerializerInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
Expand All @@ -25,7 +25,7 @@ function it_gets_a_json_string(
SerializerInterface $serializer,
EventDispatcherInterface $dispatcher,
CalendarEvent $calendarEvent,
EventInterface $event
FullCalendarEvent $event
) {
$startDate = new \DateTime();
$endDate = new \DateTime();
Expand Down
4 changes: 2 additions & 2 deletions spec/Service/SerializerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace spec\AncaRebeca\FullCalendarBundle\Service;

use AncaRebeca\FullCalendarBundle\Model\EventInterface;
use AncaRebeca\FullCalendarBundle\Model\FullCalendarEvent;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

Expand All @@ -13,7 +13,7 @@ function it_is_initializable()
$this->shouldHaveType('AncaRebeca\FullCalendarBundle\Service\Serializer');
}

function it_serialzes_data_successfully(EventInterface $event1, EventInterface $event2)
function it_serialzes_data_successfully(FullCalendarEvent $event1, FullCalendarEvent $event2)
{
$event1->toArray()->shouldBeCalled()->willReturn(['title' => 'Event 1', 'start' => '20/01/2015']);
$event2->toArray()->shouldBeCalled()->willReturn(['title' => 'Event 2', 'start' => '21/01/2015']);
Expand Down

0 comments on commit ffdd71c

Please sign in to comment.