Setup bundle and model.
authorhiroto
Fri, 30 Aug 2013 16:14:35 +0900
changeset 2 5b1b286a68e8
parent 1 790c223c73e4
child 3 5a592cf58189
Setup bundle and model.
autotweet-php/app/AppKernel.php
autotweet-php/app/config/routing.yml
autotweet-php/src/Org/W3/AutotweetBundle/Controller/DefaultController.php
autotweet-php/src/Org/W3/AutotweetBundle/DependencyInjection/Configuration.php
autotweet-php/src/Org/W3/AutotweetBundle/DependencyInjection/OrgW3AutotweetExtension.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/Post.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/PostRepository.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/Talk.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/TalkRepository.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/User.php
autotweet-php/src/Org/W3/AutotweetBundle/Entity/UserRepository.php
autotweet-php/src/Org/W3/AutotweetBundle/OrgW3AutotweetBundle.php
autotweet-php/src/Org/W3/AutotweetBundle/Resources/config/services.xml
autotweet-php/src/Org/W3/AutotweetBundle/Resources/doc/index.rst
autotweet-php/src/Org/W3/AutotweetBundle/Resources/translations/messages.fr.xlf
autotweet-php/src/Org/W3/AutotweetBundle/Resources/views/Default/index.html.twig
autotweet-php/src/Org/W3/AutotweetBundle/Tests/Controller/DefaultControllerTest.php
--- a/autotweet-php/app/AppKernel.php	Thu Aug 29 20:57:38 2013 +0900
+++ b/autotweet-php/app/AppKernel.php	Fri Aug 30 16:14:35 2013 +0900
@@ -16,6 +16,7 @@
             new Symfony\Bundle\AsseticBundle\AsseticBundle(),
             new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
             new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
+            new Org\W3\AutotweetBundle\OrgW3AutotweetBundle(),
         );
 
         if (in_array($this->getEnvironment(), array('dev', 'test'))) {
--- a/autotweet-php/app/config/routing.yml	Thu Aug 29 20:57:38 2013 +0900
+++ b/autotweet-php/app/config/routing.yml	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,5 @@
+org_w3_autotweet:
+    resource: "@OrgW3AutotweetBundle/Controller/"
+    type:     annotation
+    prefix:   /
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Controller/DefaultController.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,19 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+class DefaultController extends Controller
+{
+    /**
+     * @Route("/hello/{name}")
+     * @Template()
+     */
+    public function indexAction($name)
+    {
+        return array('name' => $name);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/DependencyInjection/Configuration.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,29 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\DependencyInjection;
+
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
+use Symfony\Component\Config\Definition\ConfigurationInterface;
+
+/**
+ * This is the class that validates and merges configuration from your app/config files
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
+ */
+class Configuration implements ConfigurationInterface
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function getConfigTreeBuilder()
+    {
+        $treeBuilder = new TreeBuilder();
+        $rootNode = $treeBuilder->root('org_w3_autotweet');
+
+        // Here you should define the parameters that are allowed to
+        // configure your bundle. See the documentation linked above for
+        // more information on that topic.
+
+        return $treeBuilder;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/DependencyInjection/OrgW3AutotweetExtension.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,28 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\Loader;
+
+/**
+ * This is the class that loads and manages your bundle configuration
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
+ */
+class OrgW3AutotweetExtension extends Extension
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function load(array $configs, ContainerBuilder $container)
+    {
+        $configuration = new Configuration();
+        $config = $this->processConfiguration($configuration, $configs);
+
+        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+        $loader->load('services.xml');
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/Post.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,183 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Post
+ *
+ * @ORM\Table()
+ * @ORM\Entity(repositoryClass="Org\W3\AutotweetBundle\Entity\PostRepository")
+ */
+class Post
+{
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="name", type="string", length=255)
+     */
+    private $name;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="content", type="text")
+     */
+    private $content;
+
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="talk_id", type="integer")
+     */
+    private $talkId;
+
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="posted_at", type="datetime")
+     */
+    private $postedAt;
+    
+    /**
+     * @ORM\ManyToOne(targetEntity="Talk", inversedBy="posts")
+     * @ORM\JoinColumn(name="talk_id", referencedColumnName="id")
+     */
+     protected $talk;
+
+
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set name
+     *
+     * @param string $name
+     * @return Post
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+    
+        return $this;
+    }
+
+    /**
+     * Get name
+     *
+     * @return string 
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * Set content
+     *
+     * @param string $content
+     * @return Post
+     */
+    public function setContent($content)
+    {
+        $this->content = $content;
+    
+        return $this;
+    }
+
+    /**
+     * Get content
+     *
+     * @return string 
+     */
+    public function getContent()
+    {
+        return $this->content;
+    }
+
+    /**
+     * Set talkId
+     *
+     * @param integer $talkId
+     * @return Post
+     */
+    public function setTalkId($talkId)
+    {
+        $this->talkId = $talkId;
+    
+        return $this;
+    }
+
+    /**
+     * Get talkId
+     *
+     * @return integer 
+     */
+    public function getTalkId()
+    {
+        return $this->talkId;
+    }
+
+    /**
+     * Set postedAt
+     *
+     * @param \DateTime $postedAt
+     * @return Post
+     */
+    public function setPostedAt($postedAt)
+    {
+        $this->postedAt = $postedAt;
+    
+        return $this;
+    }
+
+    /**
+     * Get postedAt
+     *
+     * @return \DateTime 
+     */
+    public function getPostedAt()
+    {
+        return $this->postedAt;
+    }
+
+    /**
+     * Set talk
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\Talk $talk
+     * @return Post
+     */
+    public function setTalk(\Org\W3\AutotweetBundle\Entity\Talk $talk = null)
+    {
+        $this->talk = $talk;
+    
+        return $this;
+    }
+
+    /**
+     * Get talk
+     *
+     * @return \Org\W3\AutotweetBundle\Entity\Talk 
+     */
+    public function getTalk()
+    {
+        return $this->talk;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/PostRepository.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,15 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\EntityRepository;
+
+/**
+ * PostRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class PostRepository extends EntityRepository
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/Talk.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,197 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Talk
+ *
+ * @ORM\Table()
+ * @ORM\Entity(repositoryClass="Org\W3\AutotweetBundle\Entity\TalkRepository")
+ */
+class Talk
+{
+    /**
+     * @ORM\OneToMany(targetEntity="Post", mappedBy="talk")
+     */
+    protected $posts;
+    
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="name", type="string", length=255)
+     */
+    private $name;
+    
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="kay", type="string", length=255)
+     */
+    private $kay;
+    
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="user_id", type="integer")
+     */
+    private $user_id;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="User", inversedBy="talks")
+     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
+     */
+     protected $user;
+
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set name
+     *
+     * @param string $name
+     * @return Talk
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+    
+        return $this;
+    }
+
+    /**
+     * Get name
+     *
+     * @return string 
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->posts = new \Doctrine\Common\Collections\ArrayCollection();
+    }
+    
+    /**
+     * Set user_id
+     *
+     * @param integer $userId
+     * @return Talk
+     */
+    public function setUserId($userId)
+    {
+        $this->user_id = $userId;
+    
+        return $this;
+    }
+
+    /**
+     * Get user_id
+     *
+     * @return integer 
+     */
+    public function getUserId()
+    {
+        return $this->user_id;
+    }
+
+    /**
+     * Add posts
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\Post $posts
+     * @return Talk
+     */
+    public function addPost(\Org\W3\AutotweetBundle\Entity\Post $posts)
+    {
+        $this->posts[] = $posts;
+    
+        return $this;
+    }
+
+    /**
+     * Remove posts
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\Post $posts
+     */
+    public function removePost(\Org\W3\AutotweetBundle\Entity\Post $posts)
+    {
+        $this->posts->removeElement($posts);
+    }
+
+    /**
+     * Get posts
+     *
+     * @return \Doctrine\Common\Collections\Collection 
+     */
+    public function getPosts()
+    {
+        return $this->posts;
+    }
+
+    /**
+     * Set user
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\User $user
+     * @return Talk
+     */
+    public function setUser(\Org\W3\AutotweetBundle\Entity\User $user = null)
+    {
+        $this->user = $user;
+    
+        return $this;
+    }
+
+    /**
+     * Get user
+     *
+     * @return \Org\W3\AutotweetBundle\Entity\User 
+     */
+    public function getUser()
+    {
+        return $this->user;
+    }
+
+    /**
+     * Set kay
+     *
+     * @param string $kay
+     * @return Talk
+     */
+    public function setKay($kay)
+    {
+        $this->kay = $kay;
+    
+        return $this;
+    }
+
+    /**
+     * Get kay
+     *
+     * @return string 
+     */
+    public function getKay()
+    {
+        return $this->kay;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/TalkRepository.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,15 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\EntityRepository;
+
+/**
+ * TalkRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class TalkRepository extends EntityRepository
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/User.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,109 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * User
+ *
+ * @ORM\Table()
+ * @ORM\Entity(repositoryClass="Org\W3\AutotweetBundle\Entity\UserRepository")
+ */
+class User
+{
+    /**
+     * @ORM\OneToMany(targetEntity="Talk", mappedBy="user")
+     */
+    protected $talks;
+    
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="name", type="string", length=255)
+     */
+    private $name;
+
+
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set name
+     *
+     * @param string $name
+     * @return User
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+    
+        return $this;
+    }
+
+    /**
+     * Get name
+     *
+     * @return string 
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->talks = new \Doctrine\Common\Collections\ArrayCollection();
+    }
+    
+    /**
+     * Add talks
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\Talk $talks
+     * @return User
+     */
+    public function addTalk(\Org\W3\AutotweetBundle\Entity\Talk $talks)
+    {
+        $this->talks[] = $talks;
+    
+        return $this;
+    }
+
+    /**
+     * Remove talks
+     *
+     * @param \Org\W3\AutotweetBundle\Entity\Talk $talks
+     */
+    public function removeTalk(\Org\W3\AutotweetBundle\Entity\Talk $talks)
+    {
+        $this->talks->removeElement($talks);
+    }
+
+    /**
+     * Get talks
+     *
+     * @return \Doctrine\Common\Collections\Collection 
+     */
+    public function getTalks()
+    {
+        return $this->talks;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Entity/UserRepository.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,15 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Entity;
+
+use Doctrine\ORM\EntityRepository;
+
+/**
+ * UserRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class UserRepository extends EntityRepository
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/OrgW3AutotweetBundle.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,9 @@
+<?php
+
+namespace Org\W3\AutotweetBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class OrgW3AutotweetBundle extends Bundle
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Resources/config/services.xml	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://symfony.com/schema/dic/services"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+    <!--
+    <parameters>
+        <parameter key="org_w3_autotweet.example.class">Org\W3\AutotweetBundle\Example</parameter>
+    </parameters>
+
+    <services>
+        <service id="org_w3_autotweet.example" class="%org_w3_autotweet.example.class%">
+            <argument type="service" id="service_id" />
+            <argument>plain_value</argument>
+            <argument>%parameter_name%</argument>
+        </service>
+    </services>
+    -->
+</container>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Resources/translations/messages.fr.xlf	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+    <file source-language="en" datatype="plaintext" original="file.ext">
+        <body>
+            <trans-unit id="1">
+                <source>Symfony2 is great</source>
+                <target>J'aime Symfony2</target>
+            </trans-unit>
+        </body>
+    </file>
+</xliff>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Resources/views/Default/index.html.twig	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,1 @@
+Hello {{ name }}!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autotweet-php/src/Org/W3/AutotweetBundle/Tests/Controller/DefaultControllerTest.php	Fri Aug 30 16:14:35 2013 +0900
@@ -0,0 +1,17 @@
+<?php
+
+namespace Org\W3\AutotweetBundle\Tests\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+
+class DefaultControllerTest extends WebTestCase
+{
+    public function testIndex()
+    {
+        $client = static::createClient();
+
+        $crawler = $client->request('GET', '/hello/Fabien');
+
+        $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
+    }
+}