Skip to content

Commit e552b41

Browse files
committed
Merge branch 'release/optional-entities'
2 parents d961988 + afef30c commit e552b41

7 files changed

Lines changed: 92 additions & 49 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Hackzilla\Bundle\TicketBundle\DependencyInjection\Compiler;
4+
5+
use Hackzilla\Bundle\TicketBundle\DependencyInjection\HackzillaTicketExtension;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Definition;
8+
9+
class DoctrineOrmMappingsPass extends \Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass
10+
{
11+
public function __construct($driver = null, array $namespaces = [], $managerParameters = [], $enabledParameter = false, array $aliasMap = [])
12+
{
13+
parent::__construct($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
14+
}
15+
16+
public function process(ContainerBuilder $container)
17+
{
18+
$bundleDirectory = HackzillaTicketExtension::bundleDirectory();
19+
$namespaces = [];
20+
21+
if (
22+
$container->getParameter('hackzilla_ticket.model.ticket.class') === 'Hackzilla\Bundle\TicketBundle\Entity\Ticket'
23+
||
24+
$container->getParameter('hackzilla_ticket.model.message.class') === 'Hackzilla\Bundle\TicketBundle\Entity\TicketMessage'
25+
) {
26+
$namespaces[realpath($bundleDirectory.'/Resources/config/doctrine/model')] = 'Hackzilla\Bundle\TicketBundle\Entity';
27+
}
28+
29+
$arguments = [$namespaces, '.orm.xml'];
30+
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
31+
$this->driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', [$locator]);
32+
$this->namespaces = $namespaces;
33+
34+
parent::process($container);
35+
}
36+
}

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ public function load(array $configs, ContainerBuilder $container)
2222
$configuration = new Configuration();
2323
$config = $this->processConfiguration($configuration, $configs);
2424

25-
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(self::bundleDirectory().'/Resources/config'));
2626
$loader->load('services.yml');
2727

2828
$container->setParameter('hackzilla_ticket.model.user.class', $config['user_class']);
2929
$container->setParameter('hackzilla_ticket.model.ticket.class', $config['ticket_class']);
3030
$container->setParameter('hackzilla_ticket.model.message.class', $config['message_class']);
3131
}
32+
33+
public static function bundleDirectory()
34+
{
35+
return realpath(__DIR__.'/..');
36+
}
3237
}

Entity/Ticket.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,58 @@
33
namespace Hackzilla\Bundle\TicketBundle\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
6-
use Doctrine\ORM\Mapping as ORM;
76
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
87
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
98
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
109
use Symfony\Component\Validator\Constraints as Assert;
1110

1211
/**
1312
* Ticket.
14-
*
15-
* @ORM\Table(name="ticket")
16-
* @ORM\Entity()
17-
* @ORM\HasLifecycleCallbacks
1813
*/
1914
class Ticket implements TicketInterface
2015
{
2116
/**
2217
* @var int
23-
*
24-
* @ORM\Column(name="id", type="integer")
25-
* @ORM\Id
26-
* @ORM\GeneratedValue(strategy="AUTO")
2718
*/
2819
protected $id;
2920

3021
/**
3122
* @var int
32-
*
33-
* @ORM\Column(name="user_created_id", type="integer")
3423
*/
3524
protected $userCreated;
3625
protected $userCreatedObject;
3726

3827
/**
3928
* @var int
40-
*
41-
* @ORM\Column(name="last_user_id", type="integer")
4229
*/
4330
protected $lastUser;
4431
protected $lastUserObject;
4532

4633
/**
4734
* @var \DateTime
48-
*
49-
* @ORM\Column(name="last_message", type="datetime")
5035
*/
5136
protected $lastMessage;
5237

5338
/**
54-
* @ORM\Column(name="subject", type="string", length=255)
5539
* @Assert\NotBlank()
5640
*/
5741
protected $subject;
5842

5943
/**
6044
* @var int
61-
*
62-
* @ORM\Column(name="status", type="smallint")
6345
*/
6446
protected $status;
6547

6648
/**
6749
* @var int
68-
*
69-
* @ORM\Column(name="priority", type="smallint")
7050
*/
7151
protected $priority;
7252

73-
/**
74-
* @ORM\OneToMany(targetEntity="TicketMessage", mappedBy="ticket")
75-
*/
53+
7654
protected $messages;
7755

7856
/**
79-
* @var int
80-
*
81-
* @ORM\Column(name="created_at", type="datetime")
57+
* @var \DateTime
8258
*/
8359
protected $createdAt;
8460

Entity/TicketMessage.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,48 @@
22

33
namespace Hackzilla\Bundle\TicketBundle\Entity;
44

5-
use Doctrine\ORM\Mapping as ORM;
65
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
76
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
87
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
98
use Symfony\Component\Validator\Constraints as Assert;
109

1110
/**
12-
* Message.
13-
*
14-
* @ORM\Table(name="ticket_message")
15-
* @ORM\Entity(repositoryClass="Hackzilla\Bundle\TicketBundle\Entity\TicketMessageRepository")
11+
* Ticket Message.
1612
*/
1713
class TicketMessage implements TicketMessageInterface
1814
{
1915
/**
2016
* @var int
21-
*
22-
* @ORM\Column(name="id", type="integer")
23-
* @ORM\Id
24-
* @ORM\GeneratedValue(strategy="AUTO")
2517
*/
2618
protected $id;
2719

28-
/**
29-
* @ORM\ManyToOne(targetEntity="Ticket", inversedBy="messages")
30-
* @ORM\JoinColumn(name="ticket_id", referencedColumnName="id", onDelete="CASCADE")
31-
*/
3220
protected $ticket;
3321

3422
/**
3523
* @var int
36-
*
37-
* @ORM\Column(name="user_id", type="integer")
3824
*/
3925
protected $user;
4026
protected $userObject;
4127

4228
/**
4329
* @var string
4430
*
45-
* @ORM\Column(name="message", type="text", nullable=true)
4631
* @Assert\NotBlank()
4732
*/
4833
protected $message;
4934

5035
/**
5136
* @var int
52-
*
53-
* @ORM\Column(name="status", type="smallint")
5437
*/
5538
protected $status;
5639

5740
/**
5841
* @var int
59-
*
60-
* @ORM\Column(name="priority", type="smallint")
6142
*/
6243
protected $priority;
6344

6445
/**
6546
* @var \DateTime
66-
*
67-
* @ORM\Column(name="created_at", type="datetime")
6847
*/
6948
protected $createdAt;
7049

HackzillaTicketBundle.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22

33
namespace Hackzilla\Bundle\TicketBundle;
44

5+
use Hackzilla\Bundle\TicketBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
57
use Symfony\Component\HttpKernel\Bundle\Bundle;
68

79
class HackzillaTicketBundle extends Bundle
810
{
11+
/**
12+
* @param ContainerBuilder $container
13+
*/
14+
public function build(ContainerBuilder $container)
15+
{
16+
parent::build($container);
17+
18+
$container->addCompilerPass(
19+
new DoctrineOrmMappingsPass()
20+
);
21+
}
922
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
3+
<entity name="Hackzilla\Bundle\TicketBundle\Entity\Ticket" table="ticket">
4+
<id name="id" type="integer" column="id">
5+
<generator strategy="IDENTITY"/>
6+
</id>
7+
<field name="userCreated" type="integer" column="user_created_id" precision="0" scale="0" nullable="false"/>
8+
<field name="lastUser" type="integer" column="last_user_id" precision="0" scale="0" nullable="false"/>
9+
<field name="lastMessage" type="datetime" column="last_message" precision="0" scale="0" nullable="false"/>
10+
<field name="subject" type="string" column="subject" length="255" precision="0" scale="0" nullable="false"/>
11+
<field name="status" type="smallint" column="status" precision="0" scale="0" nullable="false"/>
12+
<field name="priority" type="smallint" column="priority" precision="0" scale="0" nullable="false"/>
13+
<field name="createdAt" type="datetime" column="created_at" precision="0" scale="0" nullable="false"/>
14+
<one-to-many field="messages" target-entity="Hackzilla\Bundle\TicketBundle\Entity\TicketMessage" mapped-by="ticket" fetch="LAZY"/>
15+
</entity>
16+
</doctrine-mapping>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
3+
<entity name="Hackzilla\Bundle\TicketBundle\Entity\TicketMessage" table="ticket_message">
4+
<id name="id" type="integer" column="id">
5+
<generator strategy="IDENTITY"/>
6+
</id>
7+
<field name="user" type="integer" column="user_id" precision="0" scale="0" nullable="false"/>
8+
<field name="message" type="text" column="message" precision="0" scale="0" nullable="true"/>
9+
<field name="status" type="smallint" column="status" precision="0" scale="0" nullable="false"/>
10+
<field name="priority" type="smallint" column="priority" precision="0" scale="0" nullable="false"/>
11+
<field name="createdAt" type="datetime" column="created_at" precision="0" scale="0" nullable="false"/>
12+
<many-to-one field="ticket" target-entity="Hackzilla\Bundle\TicketBundle\Entity\Ticket" inversed-by="messages" fetch="LAZY">
13+
<join-columns>
14+
<join-column name="ticket_id" referenced-column-name="id" on-delete="CASCADE" nullable="1"/>
15+
</join-columns>
16+
</many-to-one>
17+
</entity>
18+
</doctrine-mapping>

0 commit comments

Comments
 (0)