github github
  • Home
  • Pricing and Signup
  • Training
  • Gist
  • Blog
  • Login

symfony / symfony

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
    • 1,062
    • 191
  • Source
  • Commits
  • Network
  • Pull Requests (3)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Graph
  • Members

jwage wants someone to pull 10 commits into symfony:master from jwage:master

  • Discussion
  • Commits 10
  • Files Changed 97
  • Reply

Showing 4 comments with 10 commits and 1 commit comment

#14 Closed

Here are the aliases for the orm and mongodb odm

jwage — Sat Oct 02 14:46:08 -0700 2010

No description given.

fabpot and others added some commits

Thu Sep 09 03:14:06 -0700 2010

2525998 replaced form field rendering with plain templates
8fbf196 Adding orm: and mongodb: annotation aliases to avoid conflicts. Recom...

fabpot commented

Sat Oct 02 22:24:57 -0700 2010

Why do you keep "setDefaultAnnotationNamespace"? I would have removed it to force people to use the alias. No? Actually, I have remove this call for the validation.

In Commits

fabpot and others added some commits

Sat Oct 02 22:34:56 -0700 2010

e88c0b7 [DoctrineBundle] fixed previous commit
a380692 Fix namespace collision
c2f856f [FrameworkBundle] fixed comment
ff683a6 Integrating new data fixtures code. Comment
3bc3115 Adding setLogger for data fixtures.
c6ed593 fixed unit tests
36a31ec Fixing container test.
50044cb Fixing old path to new one.

jwage commented

Wed Oct 06 11:39:47 -0700 2010

I thought about this after making the change and what do we do about code that is built for Doctrine, but not in Symfony and we want to use it in Symfony? The code might use the default annotation namespace. But they couldn't use this code without changing the annotations.

fabpot commented

Wed Oct 06 11:52:51 -0700 2010

What about adding a configuration switch?

In Commits

dpitard commented on ff683a6 src/Symfony/Bundle/DoctrineBundle/Command/LoadD...:L39

Mon Oct 11 01:29:24 -0700 2010

:( Fixtures scripts doesn't access to container service ($this->container) anymore... That could be annoying in some case.

fabpot commented

Mon Oct 11 04:05:45 -0700 2010

Can you please open a ticket on that matter, so that it is not list? Thanks.

Comment on this pull request

You must be logged in to comment on pull requests.

Active Participants

  • jwage
  • fabpot

Showing 10 unique commits by 3 authors.

8fbf1969 jwage Adding orm: and mongodb: annotation aliases to avoid conflicts. R... Sat Oct 02 14:43:30 -0700 2010
e88c0b7f fabpot [DoctrineBundle] fixed previous commit Sat Oct 02 22:34:56 -0700 2010
c2f856f0 fabpot [FrameworkBundle] fixed comment Mon Oct 04 05:01:33 -0700 2010
a3806928 ornicar Fix namespace collision Mon Oct 04 03:09:20 -0700 2010
2525998f fabpot replaced form field rendering with plain templates Thu Sep 09 03:14:06 -0700 2010
ff683a69 jwage Integrating new data fixtures code. Comment Mon Oct 04 20:23:45 -0700 2010
3bc3115d jwage Adding setLogger for data fixtures. Mon Oct 04 23:51:23 -0700 2010
c6ed5930 fabpot fixed unit tests Tue Oct 05 00:05:29 -0700 2010
36a31ece jwage Fixing container test. Tue Oct 05 00:14:07 -0700 2010
50044cbb jwage Fixing old path to new one. Tue Oct 05 00:29:00 -0700 2010

Showing 97 changed files with 1,730 additions and 2,233 deletions.

M autoload.php.dist 17 ••••
M install_vendors.sh 3 •••
M src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php 145 ••••
M src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml 9 ••••
M src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml 13 ••••
A src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php 62 •••••
M src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php 8 ••••
M src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php 8 ••••
A src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php 94 •••••
M src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml 7 ••••
A src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php 58 •••••
M src/Symfony/Bundle/FrameworkBundle/Client.php 4 ••••
M src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/errors.php 7 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/div/field_group.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/div/row.php 5 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/table/field_group.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/table/row.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/hidden.php 3 •••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/label.php 1 •
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/choice_field.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/date_field.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/date_time_field.php 2 ••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/input_field.php 1 •
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/money_field.php 6 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/percent_field.php 6 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/textarea_field.php 1 •
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/time_field.php 9 •••••
A src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/toggle_field.php 11 •••••
M src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php 2 ••
A src/Symfony/Bundle/FrameworkBundle/Templating/Form/BaseField.php 132 •••••
A src/Symfony/Bundle/FrameworkBundle/Templating/Form/Field.php 104 •••••
A src/Symfony/Bundle/FrameworkBundle/Templating/Form/FieldGroup.php 75 •••••
A src/Symfony/Bundle/FrameworkBundle/Templating/Form/FieldInterface.php 22 •••••
A src/Symfony/Bundle/FrameworkBundle/Templating/Form/Form.php 44 •••••
R src/Symfony/{Component/Form → Bundle/FrameworkBundle/Templating}/HtmlGenerator.php 48 ••••
R src/Symfony/{Component/Form → Bundle/FrameworkBundle/Templating}/HtmlGeneratorInterface.php 2 ••
M src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php 11 •••••
A src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php 240 •••••
A src/Symfony/Bundle/TwigBundle/Extension/HtmlExtension.php 62 •••••
A src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php 49 •••••
M src/Symfony/Bundle/TwigBundle/Node/HelperNode.php 8 ••••
A src/Symfony/Bundle/TwigBundle/Node/TagNode.php 62 •••••
M src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd 28 ••••
M src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml 12 •••••
A src/Symfony/Bundle/TwigBundle/Resources/views/form.twig 41 •••••
A src/Symfony/Bundle/TwigBundle/Resources/views/widgets.twig 57 •••••
A src/Symfony/Bundle/TwigBundle/TokenParser/ContentTagTokenParser.php 66 •••••
A src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php 55 •••••
A src/Symfony/Bundle/TwigBundle/TokenParser/TagTokenParser.php 57 •••••
M src/Symfony/Component/Form/CheckboxField.php 6 ••••
M src/Symfony/Component/Form/ChoiceField.php 135 ••••
M src/Symfony/Component/Form/Configurable.php 5 •••••
M src/Symfony/Component/Form/DateField.php 62 ••••
M src/Symfony/Component/Form/DateTimeField.php 11 •••••
M src/Symfony/Component/Form/Field.php 93 ••••
M src/Symfony/Component/Form/FieldGroup.php 119 ••••
M src/Symfony/Component/Form/FieldInterface.php 30 ••••
M src/Symfony/Component/Form/FileField.php 6 ••••
M src/Symfony/Component/Form/Form.php 84 ••••
M src/Symfony/Component/Form/HiddenField.php 8 ••••
M src/Symfony/Component/Form/HybridField.php 15 •••••
M src/Symfony/Component/Form/InputField.php 14 ••••
M src/Symfony/Component/Form/MoneyField.php 44 ••••
M src/Symfony/Component/Form/NumberField.php 6 ••••
M src/Symfony/Component/Form/PasswordField.php 6 ••••
M src/Symfony/Component/Form/PercentField.php 8 •••••
M src/Symfony/Component/Form/RadioField.php 6 ••••
D src/Symfony/Component/Form/Renderer/Renderer.php 88 •••••
D src/Symfony/Component/Form/Renderer/RendererInterface.php 45 •••••
D src/Symfony/Component/Form/Renderer/TableRenderer.php 52 •••••
M src/Symfony/Component/Form/TextField.php 6 ••••
M src/Symfony/Component/Form/TextareaField.php 8 ••••
M src/Symfony/Component/Form/TimeField.php 22 ••••
M src/Symfony/Component/Form/ToggleField.php 23 ••••
D src/Symfony/Component/Form/Translatable.php 20 •••••
D src/Symfony/Component/I18N/TranslatorInterface.php 22 •••••
D tests/Symfony/Tests/Component/Form/CheckboxFieldTest.php 20 •••••
M tests/Symfony/Tests/Component/Form/ChoiceFieldTest.php 278 •••••
M tests/Symfony/Tests/Component/Form/DateFieldTest.php 115 •••••
M tests/Symfony/Tests/Component/Form/DateTimeFieldTest.php 46 •••••
M tests/Symfony/Tests/Component/Form/FieldGroupTest.php 179 ••••
M tests/Symfony/Tests/Component/Form/FormTest.php 42 •••••
M tests/Symfony/Tests/Component/Form/HiddenFieldTest.php 11 •••••
D tests/Symfony/Tests/Component/Form/HtmlGeneratorTest.php 91 •••••
D tests/Symfony/Tests/Component/Form/InputFieldTest.php 33 •••••
D tests/Symfony/Tests/Component/Form/MoneyFieldTest.php 46 •••••
D tests/Symfony/Tests/Component/Form/NumberFieldTest.php 46 •••••
D tests/Symfony/Tests/Component/Form/PasswordFieldTest.php 49 •••••
D tests/Symfony/Tests/Component/Form/PercentFieldTest.php 46 •••••
D tests/Symfony/Tests/Component/Form/RadioFieldTest.php 33 •••••
D tests/Symfony/Tests/Component/Form/Renderer/RendererTestCase.php 23 •••••
D tests/Symfony/Tests/Component/Form/TextFieldTest.php 28 •••••
D tests/Symfony/Tests/Component/Form/TextareaFieldTest.php 28 •••••
M tests/Symfony/Tests/Component/Form/TimeFieldTest.php 124 •••••
D tests/Symfony/Tests/Component/Form/ToggleFieldTest.php 67 •••••
M update_vendors.sh 3 •••
Txt autoload.php.dist
  • View file @ 4027f75
... ...
@@ -6,13 +6,14 @@ use Symfony\Component\HttpFoundation\UniversalClassLoader;
6 6
 
7 7
 $loader = new UniversalClassLoader();
8 8
 $loader->registerNamespaces(array(
9  
-    'Symfony'                    => __DIR__.'/src',
10  
-    'Doctrine\\ODM\\MongoDB'     => __DIR__.'/vendor/doctrine-mongodb/lib',
11  
-    'Doctrine\\Common'           => __DIR__.'/vendor/doctrine-common/lib',
12  
-    'Doctrine\\DBAL\\Migrations' => __DIR__.'/vendor/doctrine-migrations/lib',
13  
-    'Doctrine\\DBAL'             => __DIR__.'/vendor/doctrine-dbal/lib',
14  
-    'Doctrine'                   => __DIR__.'/vendor/doctrine/lib',
15  
-    'Zend'                       => __DIR__.'/vendor/zend/library',
  9
+    'Symfony'                        => __DIR__.'/src',
  10
+    'Doctrine\\ODM\\MongoDB'         => __DIR__.'/vendor/doctrine-mongodb/lib',
  11
+    'Doctrine\\Common'               => __DIR__.'/vendor/doctrine-common/lib',
  12
+    'Doctrine\\DBAL\\Migrations'     => __DIR__.'/vendor/doctrine-migrations/lib',
  13
+    'Doctrine\\DBAL'                 => __DIR__.'/vendor/doctrine-dbal/lib',
  14
+    'Doctrine\\Common\\DataFixtures' => __DIR__.'/vendor/doctrine-data-fixtures/lib',
  15
+    'Doctrine'                       => __DIR__.'/vendor/doctrine/lib',
  16
+    'Zend'                           => __DIR__.'/vendor/zend/library',
16 17
 ));
17 18
 $loader->registerPrefixes(array(
18 19
     'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes',
... ...
@@ -26,4 +27,4 @@ set_include_path(
26 27
     __DIR__.'/vendor/phing/classes'.PATH_SEPARATOR.
27 28
     __DIR__.'/vendor/propel/runtime/lib'.PATH_SEPARATOR.
28 29
     get_include_path()
29  
-);
  30
+);
30 31
\ No newline at end of file
Txt install_vendors.sh
  • View file @ 4027f75
... ...
@@ -12,6 +12,9 @@ cd vendor
12 12
 # Doctrine ORM
13 13
 git clone git://github.com/doctrine/doctrine2.git doctrine
14 14
 
  15
+# Doctrine ORM Data Fixtures Extension
  16
+git clone git://github.com/doctrine/orm-data-fixtures doctrine-orm-data-fixtures
  17
+
15 18
 # Doctrine DBAL
16 19
 git clone git://github.com/doctrine/dbal.git doctrine-dbal
17 20
 
Txt src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php
  • View file @ 4027f75
... ...
@@ -39,6 +39,7 @@ class LoadDataFixturesDoctrineCommand extends DoctrineCommand
39 39
             ->setDescription('Load data fixtures to your database.')
40 40
             ->addOption('fixtures', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'The directory or file to load data fixtures from.')
41 41
             ->addOption('append', null, InputOption::PARAMETER_OPTIONAL, 'Whether or not to append the data fixtures.', false)
  42
+            ->addOption('em', null, InputOption::PARAMETER_REQUIRED, 'The entity manager to use for this command.')
42 43
             ->setHelp(<<<EOT
43 44
 The <info>doctrine:data:load</info> command loads data fixtures from your bundles:
44 45
 
... ...
@@ -57,7 +58,10 @@ EOT
57 58
 
58 59
     protected function execute(InputInterface $input, OutputInterface $output)
59 60
     {
60  
-        $defaultEm = $this->container->getDoctrine_ORM_EntityManagerService();
  61
+        $emName = $input->getOption('em');
  62
+        $emName = $emName ? $emName : 'default';
  63
+        $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
  64
+        $em = $this->container->get($emServiceName);
61 65
         $dirOrFile = $input->getOption('fixtures');
62 66
         if ($dirOrFile) {
63 67
             $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
... ...
@@ -69,139 +73,22 @@ EOT
69 73
                 $namespace = str_replace('/', '\\', dirname($tmp));
70 74
                 $class = basename($tmp);
71 75
 
72  
-                if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/data/fixtures/doctrine/orm')) {
  76
+                if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/DataFixtures/ORM')) {
73 77
                     $paths[] = $dir;
74 78
                 }
75 79
             }
76 80
         }
77 81
 
78  
-        $files = array();
  82
+        $loader = new \Doctrine\Common\DataFixtures\Loader();
79 83
         foreach ($paths as $path) {
80  
-            if (is_dir($path)) {
81  
-                $finder = new Finder();
82  
-                $found = iterator_to_array($finder
83  
-                    ->files()
84  
-                    ->name('*.php')
85  
-                    ->in($path));
86  
-            } else {
87  
-                $found = array($path);
88  
-            }
89  
-            $files = array_merge($files, $found);
90  
-        }
91  
-
92  
-        $ems = array();
93  
-        $emEntities = array();
94  
-        $files = array_unique($files);
95  
-        foreach ($files as $file) {
96  
-            $em = $defaultEm;
97  
-            $output->writeln(sprintf('<info>Loading data fixtures from <comment>"%s"</comment></info>', $file));
98  
-
99  
-            $before = array_keys(get_defined_vars());
100  
-            include($file);
101  
-            $after = array_keys(get_defined_vars());
102  
-            $new = array_diff($after, $before);
103  
-            $params = $em->getConnection()->getParams();
104  
-            $emName = isset($params['path']) ? $params['path']:$params['dbname'];
105  
-
106  
-            $ems[$emName] = $em;
107  
-            $emEntities[$emName] = array();
108  
-            $variables = array_values($new);
109  
-
110  
-            foreach ($variables as $variable) {
111  
-                $value = $$variable;
112  
-                if (!is_object($value) || $value instanceof \Doctrine\ORM\EntityManager) {
113  
-                    continue;
114  
-                }
115  
-                $emEntities[$emName][] = $value;
116  
-            }
117  
-            foreach ($ems as $emName => $em) {
118  
-                if (!$input->getOption('append')) {
119  
-                    $output->writeln(sprintf('<info>Purging data from entity manager named <comment>"%s"</comment></info>', $emName));
120  
-                    $this->purgeEntityManager($em);
121  
-                }
122  
-
123  
-                $entities = $emEntities[$emName];
124  
-                $numEntities = count($entities);
125  
-                $output->writeln(sprintf('<info>Persisting "%s" '.($numEntities > 1 ? 'entities' : 'entity').'</info>', count($entities)));
126  
-
127  
-                foreach ($entities as $entity) {
128  
-                    $em->persist($entity);
129  
-                }
130  
-                $output->writeln('<info>Flushing entity manager</info>');
131  
-                $em->flush();
132  
-            }
133  
-        }
134  
-    }
135  
-
136  
-    protected function purgeEntityManager(EntityManager $em)
137  
-    {
138  
-        $classes = array();
139  
-        $metadatas = $em->getMetadataFactory()->getAllMetadata();
140  
-
141  
-        foreach ($metadatas as $metadata) {
142  
-            if (!$metadata->isMappedSuperclass) {
143  
-                $classes[] = $metadata;
144  
-            }
  84
+            $loader->loadFromDirectory($path);
145 85
         }
146  
-
147  
-        $commitOrder = $this->getCommitOrder($em, $classes);
148  
-
149  
-        // Drop association tables first
150  
-        $orderedTables = $this->getAssociationTables($commitOrder);
151  
-
152  
-        // Drop tables in reverse commit order
153  
-        for ($i = count($commitOrder) - 1; $i >= 0; --$i) {
154  
-            $class = $commitOrder[$i];
155  
-
156  
-            if (($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
157  
-                || $class->isMappedSuperclass) {
158  
-                continue;
159  
-            }
160  
-
161  
-            $orderedTables[] = $class->getTableName();
162  
-        }
163  
-
164  
-        foreach($orderedTables as $tbl) {
165  
-            $em->getConnection()->executeUpdate("DELETE FROM $tbl");
166  
-        }
167  
-    }
168  
-
169  
-    protected function getCommitOrder(EntityManager $em, array $classes)
170  
-    {
171  
-        $calc = new CommitOrderCalculator;
172  
-
173  
-        foreach ($classes as $class) {
174  
-            $calc->addClass($class);
175  
-
176  
-            foreach ($class->associationMappings as $assoc) {
177  
-                if ($assoc['isOwningSide']) {
178  
-                    $targetClass = $em->getClassMetadata($assoc['targetEntity']);
179  
-
180  
-                    if ( ! $calc->hasClass($targetClass->name)) {
181  
-                            $calc->addClass($targetClass);
182  
-                    }
183  
-
184  
-                    // add dependency ($targetClass before $class)
185  
-                    $calc->addDependency($targetClass, $class);
186  
-                }
187  
-            }
188  
-        }
189  
-
190  
-        return $calc->getCommitOrder();
191  
-    }
192  
-
193  
-    protected function getAssociationTables(array $classes)
194  
-    {
195  
-        $associationTables = array();
196  
-
197  
-        foreach ($classes as $class) {
198  
-            foreach ($class->associationMappings as $assoc) {
199  
-                if ($assoc['isOwningSide'] && $assoc['type'] == ClassMetadata::MANY_TO_MANY) {
200  
-                    $associationTables[] = $assoc['joinTable']['name'];
201  
-                }
202  
-            }
203  
-        }
204  
-
205  
-        return $associationTables;
  86
+        $fixtures = $loader->getFixtures();
  87
+        $purger = new \Doctrine\Common\DataFixtures\Purger\ORMPurger($em);
  88
+        $executor = new \Doctrine\Common\DataFixtures\Executor\ORMExecutor($em, $purger);
  89
+        $executor->setLogger(function($message) use ($output) {
  90
+            $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
  91
+        });
  92
+        $executor->execute($fixtures, $input->getOption('append'));
206 93
     }
207  
-}
  94
+}
208 95
\ No newline at end of file
Txt src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml
  • View file @ 4027f75
... ...
@@ -7,15 +7,16 @@
7 7
     <parameters>
8 8
         <parameter key="doctrine.dbal.default_connection">default</parameter>
9 9
         <parameter key="doctrine.dbal.connection_class">Doctrine\DBAL\Connection</parameter>
10  
-
  10
+        <parameter key="doctrine.dbal.logger.debug_class">Doctrine\DBAL\Logging\DebugStack</parameter>
  11
+        <parameter key="doctrine.dbal.logger_class">Symfony\Bundle\DoctrineBundle\Logger\DbalLogger</parameter>
11 12
         <parameter key="doctrine.data_collector.class">Symfony\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector</parameter>
12 13
         <parameter key="doctrine.dbal.default_connection">default</parameter>
13 14
     </parameters>
14 15
 
15 16
     <services>
16  
-        <service id="doctrine.dbal.logger.debug" class="Doctrine\DBAL\Logging\DebugStack" />
  17
+        <service id="doctrine.dbal.logger.debug" class="%doctrine.dbal.logger.debug_class%" />
17 18
 
18  
-        <service id="doctrine.dbal.logger" class="Symfony\Bundle\DoctrineBundle\Logger\DbalLogger">
  19
+        <service id="doctrine.dbal.logger" class="%doctrine.dbal.logger_class%">
19 20
             <argument type="service" id="logger" on-invalid="null" />
20 21
         </service>
21 22
 
... ...
@@ -24,4 +25,4 @@
24 25
             <argument type="service" id="doctrine.dbal.logger" />
25 26
         </service>
26 27
     </services>
27  
-</container>
  28
+</container>
28 29
\ No newline at end of file
Txt src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
  • View file @ 4027f75
... ...
@@ -42,22 +42,25 @@
42 42
 
43 43
     <services>
44 44
         <!--- Annotation Metadata Driver Service -->
45  
-        <service id="doctrine.orm.metadata_driver.annotation" class="Doctrine\ORM\Mapping\Driver\AnnotationDriver">
  45
+        <service id="doctrine.orm.metadata_driver.annotation" class="%doctrine.orm.metadata.annotation_class%">
46 46
             <argument type="service" id="doctrine.orm.metadata_driver.annotation.reader" />
47 47
             <argument>%doctrine.orm.metadata_driver.entity_dirs%</argument>
48 48
         </service>
49 49
 
50  
-        <service id="doctrine.orm.metadata_driver.annotation.reader" class="Doctrine\Common\Annotations\AnnotationReader">
51  
-            <call method="setDefaultAnnotationNamespace"><argument>Doctrine\ORM\Mapping\</argument></call>
  50
+        <service id="doctrine.orm.metadata_driver.annotation.reader" class="%doctrine.orm.metadata.annotation_reader_class%">
  51
+            <call method="setAnnotationNamespaceAlias">
  52
+              <argument>Doctrine\ORM\Mapping\</argument>
  53
+              <argument>orm</argument>
  54
+            </call>
52 55
         </service>
53 56
 
54 57
         <!--- XML Metadata Driver Service -->
55  
-        <service id="doctrine.orm.metadata_driver.xml" class="Doctrine\ORM\Mapping\Driver\XmlDriver">
  58
+        <service id="doctrine.orm.metadata_driver.xml" class="%doctrine.orm.metadata.xml_class%">
56 59
             <argument>%doctrine.orm.metadata_driver.mapping_dirs%</argument>
57 60
         </service>
58 61
 
59 62
         <!--- YAML Metadata Driver Service -->
60  
-        <service id="doctrine.orm.metadata_driver.yml" class="Doctrine\ORM\Mapping\Driver\YamlDriver">
  63
+        <service id="doctrine.orm.metadata_driver.yml" class="%doctrine.orm.metadata.yml_class%">
61 64
             <argument>%doctrine.orm.metadata_driver.mapping_dirs%</argument>
62 65
         </service>
63 66
     </services>
Txt src/Symfony/Bundle/DoctrineBundle/Tests/ContainerTest.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,62 @@
  1
+<?php
  2
+
  3
+/*
  4
+ * This file is part of the Symfony package.
  5
+ *
  6
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7
+ *
  8
+ * For the full copyright and license information, please view the LICENSE
  9
+ * file that was distributed with this source code.
  10
+ */
  11
+
  12
+namespace Symfony\Bundle\DoctrineBundle\Tests;
  13
+
  14
+use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  15
+use Symfony\Component\DependencyInjection\ContainerBuilder;
  16
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  17
+use Symfony\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
  18
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  19
+
  20
+class ContainerTest extends TestCase
  21
+{
  22
+    public function getContainer()
  23
+    {
  24
+        $container = new ContainerBuilder(new ParameterBag(array(
  25
+            'kernel.bundle_dirs' => array(),
  26
+            'kernel.bundles'     => array(),
  27
+            'kernel.cache_dir'   => sys_get_temp_dir(),
  28
+        )));
  29
+        $loader = new DoctrineExtension();
  30
+        $container->registerExtension($loader);
  31
+        $loader->dbalLoad(array(), $container);
  32
+        $loader->ormLoad(array(), $container);
  33
+
  34
+        $dumper = new PhpDumper($container);
  35
+        $code = $dumper->dump(array('class' => 'DoctrineBundleTestsProjectServiceContainer'));
  36
+        eval(str_replace('<?php', null, $code));
  37
+        return new \DoctrineBundleTestsProjectServiceContainer;
  38
+    }
  39
+
  40
+    public function testContainer()
  41
+    {
  42
+        $container = $this->getContainer();
  43
+        $this->assertInstanceOf('Doctrine\DBAL\Logging\DebugStack', $container->get('doctrine.dbal.logger.debug'));
  44
+        $this->assertInstanceOf('Doctrine\DBAL\Logging\DebugStack', $container->get('doctrine.dbal.logger'));
  45
+        $this->assertInstanceOf('Symfony\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector', $container->get('doctrine.data_collector'));
  46
+        $this->assertInstanceOf('Doctrine\DBAL\Configuration', $container->get('doctrine.dbal.default_connection.configuration'));
  47
+        $this->assertInstanceOf('Doctrine\Common\EventManager', $container->get('doctrine.dbal.default_connection.event_manager'));
  48
+        $this->assertInstanceOf('Doctrine\DBAL\Connection', $container->get('doctrine.dbal.default_connection'));
  49
+        $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $container->get('doctrine.orm.metadata_driver.annotation'));
  50
+        $this->assertInstanceOf('Doctrine\Common\Annotations\AnnotationReader', $container->get('doctrine.orm.metadata_driver.annotation.reader'));
  51
+        $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $container->get('doctrine.orm.metadata_driver.xml'));
  52
+        $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $container->get('doctrine.orm.metadata_driver.yml'));
  53
+        $this->assertInstanceOf('Doctrine\ORM\Configuration', $container->get('doctrine.orm.default_configuration'));
  54
+        $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\DriverChain', $container->get('doctrine.orm.metadata_driver'));
  55
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.orm.default_metadata_cache'));
  56
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.orm.default_query_cache'));
  57
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.orm.default_result_cache'));
  58
+        $this->assertInstanceOf('Doctrine\ORM\EntityManager', $container->get('doctrine.orm.default_entity_manager'));
  59
+        $this->assertInstanceOf('Doctrine\DBAL\Connection', $container->get('database_connection'));
  60
+        $this->assertInstanceOf('Doctrine\ORM\EntityManager', $container->get('doctrine.orm.entity_manager'));
  61
+    }
  62
+}
0 63
\ No newline at end of file
Txt src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php
  • View file @ 4027f75
... ...
@@ -21,16 +21,16 @@ class CreateSchemaDoctrineODMCommand extends CreateCommand
21 21
         parent::configure();
22 22
 
23 23
         $this
24  
-            ->setName('doctrine:odm:schema:create')
  24
+            ->setName('doctrine:mongodb:schema:create')
25 25
             ->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
26 26
             ->setHelp(<<<EOT
27  
-The <info>doctrine:odm:schema:create</info> command creates the default document manager's schema:
  27
+The <info>doctrine:mongodb:schema:create</info> command creates the default document manager's schema:
28 28
 
29  
-  <info>./symfony doctrine:odm:schema:create</info>
  29
+  <info>./symfony doctrine:mongodb:schema:create</info>
30 30
 
31 31
 You can also optionally specify the name of a document manager to create the schema for:
32 32
 
33  
-  <info>./symfony doctrine:odm:schema:create --dm=default</info>
  33
+  <info>./symfony doctrine:mongodb:schema:create --dm=default</info>
34 34
 EOT
35 35
         );
36 36
     }
Txt src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php
  • View file @ 4027f75
... ...
@@ -21,16 +21,16 @@ class DropSchemaDoctrineODMCommand extends DropCommand
21 21
         parent::configure();
22 22
 
23 23
         $this
24  
-            ->setName('doctrine:odm:schema:drop')
  24
+            ->setName('doctrine:mongodb:schema:drop')
25 25
             ->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
26 26
             ->setHelp(<<<EOT
27  
-The <info>doctrine:odm:schema:drop</info> command drops the default document manager's schema:
  27
+The <info>doctrine:mongodb:schema:drop</info> command drops the default document manager's schema:
28 28
 
29  
-  <info>./symfony doctrine:odm:schema:drop</info>
  29
+  <info>./symfony doctrine:mongodb:schema:drop</info>
30 30
 
31 31
 You can also optionally specify the name of a document manager to drop the schema for:
32 32
 
33  
-  <info>./symfony doctrine:odm:schema:drop --dm=default</info>
  33
+  <info>./symfony doctrine:mongodb:schema:drop --dm=default</info>
34 34
 EOT
35 35
         );
36 36
     }
Txt src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,94 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\DoctrineMongoDBBundle\Command;
  4
+
  5
+use Symfony\Component\Console\Input\InputArgument;
  6
+use Symfony\Component\Console\Input\InputOption;
  7
+use Symfony\Component\Console\Input\InputInterface;
  8
+use Symfony\Component\Console\Output\OutputInterface;
  9
+use Symfony\Component\Console\Output\Output;
  10
+use Symfony\Component\Finder\Finder;
  11
+use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
  12
+use Doctrine\Common\Cli\Configuration;
  13
+use Doctrine\Common\Cli\CliController as DoctrineCliController;
  14
+use Doctrine\ODM\MongoDB\DocumentManager;
  15
+use Doctrine\ODM\MongoDB\Internal\CommitOrderCalculator;
  16
+use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
  17
+
  18
+/*
  19
+ * This file is part of the Symfony framework.
  20
+ *
  21
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  22
+ *
  23
+ * This source file is subject to the MIT license that is bundled
  24
+ * with this source code in the file LICENSE.
  25
+ */
  26
+
  27
+/**
  28
+ * Load data fixtures from bundles.
  29
+ *
  30
+ * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  31
+ * @author     Jonathan H. Wage <jonwage@gmail.com>
  32
+ */
  33
+class LoadDataFixturesDoctrineODMCommand extends DoctrineODMCommand
  34
+{
  35
+    protected function configure()
  36
+    {
  37
+        $this
  38
+            ->setName('doctrine:mongodb:data:load')
  39
+            ->setDescription('Load data fixtures to your database.')
  40
+            ->addOption('fixtures', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'The directory or file to load data fixtures from.')
  41
+            ->addOption('append', null, InputOption::PARAMETER_OPTIONAL, 'Whether or not to append the data fixtures.', false)
  42
+            ->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
  43
+            ->setHelp(<<<EOT
  44
+The <info>doctrine:mongodb:data:load</info> command loads data fixtures from your bundles:
  45
+
  46
+  <info>./symfony doctrine:mongodb:data:load</info>
  47
+
  48
+You can also optionally specify the path to fixtures with the <info>--fixtures</info> option:
  49
+
  50
+  <info>./symfony doctrine:mongodb:data:load --fixtures=/path/to/fixtures1 --fixtures=/path/to/fixtures2</info>
  51
+
  52
+If you want to append the fixtures instead of flushing the database first you can use the <info>--append</info> option:
  53
+
  54
+  <info>./symfony doctrine:mongodb:data:load --append</info>
  55
+EOT
  56
+        );
  57
+    }
  58
+
  59
+    protected function execute(InputInterface $input, OutputInterface $output)
  60
+    {
  61
+        $dmName = $input->getOption('dm');
  62
+        $dmName = $dmName ? $dmName : 'default';
  63
+        $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
  64
+        $dm = $this->container->get($dmServiceName);
  65
+        $dirOrFile = $input->getOption('fixtures');
  66
+        if ($dirOrFile) {
  67
+            $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
  68
+        } else {
  69
+            $paths = array();
  70
+            $bundleDirs = $this->container->getKernelService()->getBundleDirs();
  71
+            foreach ($this->container->getKernelService()->getBundles() as $bundle) {
  72
+                $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
  73
+                $namespace = str_replace('/', '\\', dirname($tmp));
  74
+                $class = basename($tmp);
  75
+
  76
+                if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/DataFixtures/MongoDB')) {
  77
+                    $paths[] = $dir;
  78
+                }
  79
+            }
  80
+        }
  81
+
  82
+        $loader = new \Doctrine\Common\DataFixtures\Loader();
  83
+        foreach ($paths as $path) {
  84
+            $loader->loadFromDirectory($path);
  85
+        }
  86
+        $fixtures = $loader->getFixtures();
  87
+        $purger = new \Doctrine\Common\DataFixtures\Purger\MongoDBPurger($dm);
  88
+        $executor = new \Doctrine\Common\DataFixtures\Executor\MongoDBExecutor($dm, $purger);
  89
+        $executor->setLogger(function($message) use ($output) {
  90
+            $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
  91
+        });
  92
+        $executor->execute($fixtures, $input->getOption('append'));
  93
+    }
  94
+}
0 95
\ No newline at end of file
Txt src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml
  • View file @ 4027f75
... ...
@@ -56,7 +56,10 @@
56 56
     </service>
57 57
     <service id="doctrine.odm.mongodb.metadata.annotation_reader" class="%doctrine.odm.mongodb.metadata.annotation_reader_class%">
58 58
       <argument type="service" id="doctrine.odm.mongodb.cache" />
59  
-      <call method="setDefaultAnnotationNamespace"><argument>%doctrine.odm.mongodb.metadata.annotation_default_namespace%</argument></call>
  59
+      <call method="setAnnotationNamespaceAlias">
  60
+        <argument>Doctrine\ODM\MongoDB\Mapping\</argument>
  61
+        <argument>mongodb</argument>
  62
+      </call>
60 63
     </service>
61 64
     <service id="doctrine.odm.mongodb.metadata.xml" class="%doctrine.odm.mongodb.metadata.xml_class%"><argument>%doctrine.odm.mongodb.xml_mapping_dirs%</argument></service>
62 65
     <service id="doctrine.odm.mongodb.metadata.yml" class="%doctrine.odm.mongodb.metadata.yml_class%"><argument>%doctrine.odm.mongodb.yml_mapping_dirs%</argument></service>
... ...
@@ -73,4 +76,4 @@
73 76
       <argument type="service" id="doctrine.odm.mongodb.logger" />
74 77
     </service>
75 78
   </services>
76  
-</container>
  79
+</container>
77 80
\ No newline at end of file
Txt src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,58 @@
  1
+<?php
  2
+
  3
+/*
  4
+ * This file is part of the Symfony package.
  5
+ *
  6
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7
+ *
  8
+ * For the full copyright and license information, please view the LICENSE
  9
+ * file that was distributed with this source code.
  10
+ */
  11
+
  12
+namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests;
  13
+
  14
+use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  15
+use Symfony\Component\DependencyInjection\ContainerBuilder;
  16
+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  17
+use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
  18
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  19
+
  20
+class ContainerTest extends TestCase
  21
+{
  22
+    public function getContainer()
  23
+    {
  24
+        $container = new ContainerBuilder(new ParameterBag(array(
  25
+            'kernel.bundle_dirs' => array(),
  26
+            'kernel.bundles'     => array(),
  27
+            'kernel.cache_dir'   => sys_get_temp_dir(),
  28
+        )));
  29
+        $loader = new DoctrineMongoDBExtension();
  30
+        $container->registerExtension($loader);
  31
+        $loader->mongodbLoad(array(), $container);
  32
+
  33
+        $dumper = new PhpDumper($container);
  34
+        $code = $dumper->dump(array('class' => 'DoctrineMongoDBBundleTestsProjectServiceContainer'));
  35
+        eval(str_replace('<?php', null, $code));
  36
+        return new \DoctrineMongoDBBundleTestsProjectServiceContainer;
  37
+    }
  38
+
  39
+    public function testContainer()
  40
+    {
  41
+        $container = $this->getContainer();
  42
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.metadata.chain'));
  43
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', $container->get('doctrine.odm.mongodb.metadata.annotation'));
  44
+        $this->assertInstanceOf('Doctrine\Common\Annotations\AnnotationReader', $container->get('doctrine.odm.mongodb.metadata.annotation_reader'));
  45
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', $container->get('doctrine.odm.mongodb.metadata.xml'));
  46
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', $container->get('doctrine.odm.mongodb.metadata.yml'));
  47
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache.array'));
  48
+        $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger', $container->get('doctrine.odm.mongodb.logger'));
  49
+        $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\DataCollector\DoctrineMongoDBDataCollector', $container->get('doctrine.odm.mongodb.data_collector'));
  50
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mongo', $container->get('doctrine.odm.mongodb.default_connection'));
  51
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Configuration', $container->get('doctrine.odm.mongodb.default_configuration'));
  52
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.metadata'));
  53
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.default_metadata_cache'));
  54
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.default_document_manager'));
  55
+        $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache'));
  56
+        $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.document_manager'));
  57
+    }
  58
+}
Txt src/Symfony/Bundle/FrameworkBundle/Client.php
  • View file @ 4027f75
... ...
@@ -7,7 +7,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
7 7
 use Symfony\Component\HttpKernel\Client as BaseClient;
8 8
 use Symfony\Component\BrowserKit\History;
9 9
 use Symfony\Component\BrowserKit\CookieJar;
10  
-use Symfony\Component\HttpKernel\Profiler\Profiler;
  10
+use Symfony\Component\HttpKernel\Profiler\Profiler as HttpProfiler;
11 11
 use Symfony\Component\HttpFoundation\Request;
12 12
 use Symfony\Component\HttpFoundation\Response;
13 13
 
... ...
@@ -67,7 +67,7 @@ class Client extends BaseClient
67 67
     /**
68 68
      * Gets a profiler for the current Response.
69 69
      *
70  
-     * @return Profiler A Profiler instance
  70
+     * @return HttpProfiler A Profiler instance
71 71
      */
72 72
     public function getProfiler()
73 73
     {
Txt src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml
  • View file @ 4027f75
... ...
@@ -19,6 +19,8 @@
19 19
         <parameter key="templating.helper.session.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper</parameter>
20 20
         <parameter key="templating.helper.code.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper</parameter>
21 21
         <parameter key="templating.helper.translator.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper</parameter>
  22
+        <parameter key="templating.form.class">Symfony\Bundle\FrameworkBundle\Templating\Form\Form</parameter>
  23
+        <parameter key="templating.html.generator.class">Symfony\Bundle\FrameworkBundle\Templating\HtmlGenerator</parameter>
22 24
         <parameter key="templating.output_escaper">false</parameter>
23 25
         <parameter key="templating.assets.version">null</parameter>
24 26
         <parameter key="templating.assets.base_urls" type="collection"></parameter>
... ...
@@ -26,6 +28,8 @@
26 28
     </parameters>
27 29
 
28 30
     <services>
  31
+        <service id="templating.html.generator" class="%templating.html.generator.class%" />
  32
+
29 33
         <service id="templating.engine" class="%templating.engine.class%">
30 34
             <argument type="service" id="service_container" />
31 35
             <argument type="service" id="templating.loader" />
... ...
@@ -101,6 +105,11 @@
101 105
             <argument type="service" id="translator" />
102 106
         </service>
103 107
 
  108
+        <service id="templating.form" class="%templating.form.class%">
  109
+            <argument type="service" id="templating" />
  110
+            <argument type="service" id="templating.html.generator" />
  111
+        </service>
  112
+
104 113
         <service id="templating.loader" alias="templating.loader.filesystem" />
105 114
 
106 115
         <service id="templating" alias="templating.engine" />
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/errors.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,7 @@
  1
+<?php if ($errors): ?>
  2
+    <ul>
  3
+        <?php foreach ($errors as $error): ?>
  4
+            <li><?php echo $view['translator']->trans($error[0], $error[1], 'validators') ?></li>
  5
+        <?php endforeach; ?>
  6
+    </ul>
  7
+<?php endif; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/div/field_group.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<?php echo $group->errors() ?>
  2
+
  3
+<div>
  4
+    <?php foreach ($group as $field): ?>
  5
+        <?php echo $field->render() ?>
  6
+    <?php endforeach; ?>
  7
+</div>
  8
+
  9
+<?php echo $group->hidden() ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/div/row.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,5 @@
  1
+<div>
  2
+    <?php echo $field->label() ?>
  3
+    <?php echo $field->errors() ?>
  4
+    <?php echo $field->field() ?>
  5
+</div>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/table/field_group.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<?php echo $group->errors() ?>
  2
+
  3
+<table>
  4
+    <?php foreach ($group as $field): ?>
  5
+        <?php echo $field->render() ?>
  6
+    <?php endforeach; ?>
  7
+</table>
  8
+
  9
+<?php echo $group->hidden() ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/group/table/row.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<tr>
  2
+    <th>
  3
+        <?php echo $field->label() ?>
  4
+    </th>
  5
+    <td>
  6
+        <?php echo $field->errors() ?>
  7
+        <?php echo $field->widget() ?>
  8
+    </td>
  9
+</tr>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/hidden.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,3 @@
  1
+<?php foreach ($hidden as $field): ?>
  2
+    <?php echo $field->widget() ?>
  3
+<?php endforeach; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/label.php
  • View file @ 4027f75
... ...
@@ -0,0 +1 @@
  1
+<label for="<?php echo $id ?>"><?php echo $view['translator']->trans($label) ?></label>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/choice_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<?php if ($origin->getOption('expanded')): ?>
  2
+    <?php foreach ($field as $child): ?>
  3
+        <?php echo $child->widget() ?>
  4
+    <?php endforeach; ?>
  5
+<?php else: ?>
  6
+    <?php echo $generator->contentTag('select',
  7
+        $generator->choices($origin->getPreferredChoices(), $origin->getOtherChoices(), $origin->getEmptyValue(), $origin->getSelected()),
  8
+        $attributes) ?>
  9
+<?php endif; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/date_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<?php if ($origin->isField()): ?>
  2
+    <?php echo $generator->tag('input', $attributes) ?>
  3
+<?php else: ?>
  4
+    <?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
  5
+        $field['year']->widget($attributes),
  6
+        $field['month']->widget($attributes),
  7
+        $field['day']->widget($attributes),
  8
+    ), $origin->getPattern()) ?>
  9
+<?php endif; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/date_time_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,2 @@
  1
+<?php echo $field['date']->widget($attributes) ?>
  2
+<?php echo $field['time']->widget($attributes) ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/input_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1 @@
  1
+<?php echo $generator->tag('input', $attributes) ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/money_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,6 @@
  1
+<?php echo str_replace('{{ widget }}', $view->render('FrameworkBundle:Form:widget/input_field.php', array(
  2
+    'field'      => $field,
  3
+    'origin'     => $origin,
  4
+    'attributes' => $attributes,
  5
+    'generator'  => $generator,
  6
+)), $origin->getPattern()) ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/percent_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,6 @@
  1
+<?php echo $view->render('FrameworkBundle:Form:widget/input_field.php', array(
  2
+    'field'      => $field,
  3
+    'origin'     => $origin,
  4
+    'attributes' => $attributes,
  5
+    'generator'  => $generator,
  6
+)) ?> %
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/textarea_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1 @@
  1
+<?php echo $generator->contentTag('textarea', $view->escape($field->getDisplayedData()), $attributes) ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/time_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,9 @@
  1
+<?php if ($origin->isField()): ?>
  2
+    <?php echo $generator->tag('input', $attributes) ?>
  3
+<?php else: ?>
  4
+    <?php echo $field['hour']->widget($attributes).':'.$field['minute']->widget($attributes) ?>
  5
+
  6
+    <?php if ($origin->getOption('with_seconds')): ?>
  7
+        <?php echo ':'.$field['second']->widget($attributes) ?>
  8
+    <?php endif; ?>
  9
+<?php endif; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget/toggle_field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,11 @@
  1
+<?php echo $view->render('FrameworkBundle:Form:widget/input_field.php', array(
  2
+        'field'      => $field,
  3
+        'origin'     => $origin,
  4
+        'attributes' => $attributes,
  5
+        'generator'  => $generator,
  6
+    ))
  7
+?>
  8
+
  9
+<?php if ($label = $origin->getOption('label')): ?>
  10
+    <?php echo $generator->contentTag('label', $view['translator']->trans($label), array('for' => $origin->getId())) ?>
  11
+<?php endif; ?>
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php
  • View file @ 4027f75
... ...
@@ -137,7 +137,7 @@ class Engine extends BaseEngine
137 137
     }
138 138
 
139 139
     // parses template names following the following pattern:
140  
-    // bundle:section:template(.format)(.renderer)
  140
+    // bundle:section:template(.format).renderer
141 141
     public function splitTemplateName($name, array $defaults = array())
142 142
     {
143 143
         $parts = explode(':', $name);
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Form/BaseField.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,132 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating\Form;
  4
+
  5
+use Symfony\Component\Templating\Engine;
  6
+use Symfony\Component\Form\FieldInterface as FormFieldInterface;
  7
+use Symfony\Component\Form\HybridField;
  8
+use Symfony\Component\Form\FieldGroupInterface;
  9
+use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;
  10
+use Symfony\Component\OutputEscaper\SafeDecoratorInterface;
  11
+
  12
+/*
  13
+ * This file is part of the Symfony framework.
  14
+ *
  15
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  16
+ *
  17
+ * This source file is subject to the MIT license that is bundled
  18
+ * with this source code in the file LICENSE.
  19
+ */
  20
+
  21
+/**
  22
+ * 
  23
+ *
  24
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  25
+ */
  26
+abstract class BaseField implements FieldInterface, SafeDecoratorInterface
  27
+{
  28
+    protected $engine;
  29
+    protected $field;
  30
+    protected $generator;
  31
+    protected $theme;
  32
+    protected $doctype;
  33
+
  34
+    public function __construct(FormFieldInterface $field, Engine $engine, HtmlGeneratorInterface $generator, $theme, $doctype)
  35
+    {
  36
+        $this->field = $field;
  37
+        $this->engine = $engine;
  38
+        $this->generator = $generator;
  39
+        $this->theme = $theme;
  40
+    }
  41
+
  42
+    public function getIterator()
  43
+    {
  44
+        if (!$this->field instanceof FieldGroupInterface) {
  45
+            throw new \LogicException(sprintf('Cannot iterate a non group field (%s)', $this->field->getKey()));
  46
+        }
  47
+
  48
+        $fields = array();
  49
+        foreach ($this->field->getFields() as $field) {
  50
+            if (!$field->isHidden()) {
  51
+                $fields[] = $field;
  52
+            }
  53
+        }
  54
+
  55
+        return new \ArrayIterator($this->wrapFields($fields));
  56
+    }
  57
+
  58
+    /**
  59
+     * Returns true if the bound field exists (implements the \ArrayAccess interface).
  60
+     *
  61
+     * @param string $key The key of the bound field
  62
+     *
  63
+     * @return Boolean true if the widget exists, false otherwise
  64
+     */
  65
+    public function offsetExists($key)
  66
+    {
  67
+        if (!$this->field instanceof FieldGroupInterface) {
  68
+            throw new \LogicException(sprintf('Cannot access a non group field as an array (%s)', $this->field->getKey()));
  69
+        }
  70
+
  71
+        return $this->field->has($key);
  72
+    }
  73
+
  74
+    /**
  75
+     * Returns the form field associated with the name (implements the \ArrayAccess interface).
  76
+     *
  77
+     * @param string $key The offset of the value to get
  78
+     *
  79
+     * @return Field A form field instance
  80
+     */
  81
+    public function offsetGet($key)
  82
+    {
  83
+        if (!$this->field instanceof FieldGroupInterface) {
  84
+            throw new \LogicException(sprintf('Cannot access a non group field as an array (%s)', $this->field->getKey()));
  85
+        }
  86
+
  87
+        return $this->createField($this->field->get($key));
  88
+    }
  89
+
  90
+    /**
  91
+     * Throws an exception saying that values cannot be set (implements the \ArrayAccess interface).
  92
+     *
  93
+     * @param string $offset (ignored)
  94
+     * @param string $value (ignored)
  95
+     *
  96
+     * @throws \LogicException
  97
+     */
  98
+    public function offsetSet($key, $field)
  99
+    {
  100
+        throw new \LogicException('This helper is read-only');
  101
+    }
  102
+
  103
+    /**
  104
+     * Throws an exception saying that values cannot be unset (implements the \ArrayAccess interface).
  105
+     *
  106
+     * @param string $key
  107
+     *
  108
+     * @throws \LogicException
  109
+     */
  110
+    public function offsetUnset($key)
  111
+    {
  112
+        throw new \LogicException('This helper is read-only');
  113
+    }
  114
+
  115
+    protected function wrapFields($fields)
  116
+    {
  117
+        foreach ($fields as $id => $field) {
  118
+            $fields[$id] = $this->createField($field);
  119
+        }
  120
+
  121
+        return $fields;
  122
+    }
  123
+
  124
+    protected function createField(FormFieldInterface $field)
  125
+    {
  126
+        if ($field instanceof Form || get_class($field) === 'Symfony\Component\Form\FieldGroup') {
  127
+            return new FieldGroup($field, $this->engine, $this->generator, $this->theme, $this->doctype);
  128
+        }
  129
+
  130
+        return new Field($field, $this->engine, $this->generator, $this->theme, $this->doctype);
  131
+    }
  132
+}
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Form/Field.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,104 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating\Form;
  4
+
  5
+/*
  6
+ * This file is part of the Symfony framework.
  7
+ *
  8
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9
+ *
  10
+ * This source file is subject to the MIT license that is bundled
  11
+ * with this source code in the file LICENSE.
  12
+ */
  13
+
  14
+/**
  15
+ * Field wraps a Form\FieldInterface instance.
  16
+ *
  17
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18
+ */
  19
+class Field extends BaseField
  20
+{
  21
+    static protected $cache = array();
  22
+
  23
+    public function render($template = null)
  24
+    {
  25
+        if ($this->field instanceof Form || get_class($this->field) === 'Symfony\Component\Form\FieldGroup') {
  26
+            throw new \LogicException(sprintf('Cannot render a group field as a row (%s)', $this->field->getKey()));
  27
+        }
  28
+
  29
+        if (null === $template) {
  30
+            $template = sprintf('FrameworkBundle:Form:group/%s/row.php', $this->theme);
  31
+        }
  32
+
  33
+        return $this->engine->render($template, array('field' => $this));
  34
+    }
  35
+
  36
+    public function data()
  37
+    {
  38
+        return $this->field->getData();
  39
+    }
  40
+
  41
+    public function widget(array $attributes = array(), $template = null)
  42
+    {
  43
+        if ($this->field instanceof Form || get_class($this->field) === 'Symfony\Component\Form\FieldGroup') {
  44
+            throw new \LogicException(sprintf('Cannot render a group field (%s)', $this->field->getKey()));
  45
+        }
  46
+
  47
+        if (null === $template) {
  48
+            $template = $this->getTemplate();
  49
+        }
  50
+
  51
+        return $this->engine->render($template, array(
  52
+            'field'      => $this,
  53
+            'origin'     => $this->field,
  54
+            'attributes' => array_merge($this->field->getAttributes(), $attributes),
  55
+            'generator'  => $this->generator,
  56
+        ));
  57
+    }
  58
+
  59
+    public function label($label, $template = null)
  60
+    {
  61
+        if (null === $template) {
  62
+            $template = 'FrameworkBundle:Form:label.php';
  63
+        }
  64
+
  65
+        return $this->engine->render($template, array(
  66
+            'field' => $this,
  67
+            'id'    => $this->field->getId(),
  68
+            'key'   => $this->field->getKey(),
  69
+            'label' => $label ? $label : ucfirst(strtolower(str_replace('_', ' ', $this->field->getKey())))
  70
+        ));
  71
+    }
  72
+
  73
+    public function errors($template = null)
  74
+    {
  75
+        if (null === $template) {
  76
+            $template = 'FrameworkBundle:Form:errors.php';
  77
+        }
  78
+
  79
+        return $this->engine->render($template, array('field' => $this, 'errors' => $this->field->getErrors()));
  80
+    }
  81
+
  82
+    protected function getTemplate()
  83
+    {
  84
+        $class = get_class($this->field);
  85
+
  86
+        if (isset(self::$cache[$class])) {
  87
+            return self::$cache[$class];
  88
+        }
  89
+
  90
+        // find a template for the given class or one of its parents
  91
+        do {
  92
+            $parts = explode('\\', $class);
  93
+            $c = array_pop($parts);
  94
+
  95
+            $underscore = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($c, '_', '.')));
  96
+
  97
+            if ($this->engine->exists($template = 'FrameworkBundle:Form:widget/'.$underscore.'.php')) {
  98
+                return self::$cache[$class] = $template;
  99
+            }
  100
+        } while (false !== $class = get_parent_class($class));
  101
+
  102
+        throw new \RuntimeException(sprintf('Unable to find a template to render the "%s" widget.', $this->field->getKey()));
  103
+    }
  104
+}
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Form/FieldGroup.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,75 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating\Form;
  4
+
  5
+/*
  6
+ * This file is part of the Symfony framework.
  7
+ *
  8
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9
+ *
  10
+ * This source file is subject to the MIT license that is bundled
  11
+ * with this source code in the file LICENSE.
  12
+ */
  13
+
  14
+/**
  15
+ * FieldGroup wraps a Form\FieldGroupInterface instance.
  16
+ *
  17
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18
+ */
  19
+class FieldGroup extends BaseField
  20
+{
  21
+    /**
  22
+     * Renders the form tag.
  23
+     *
  24
+     * This method only renders the opening form tag.
  25
+     * You need to close it after the form rendering.
  26
+     *
  27
+     * This method takes into account the multipart widgets.
  28
+     *
  29
+     * @param  string $url         The URL for the action
  30
+     * @param  array  $attributes  An array of HTML attributes
  31
+     *
  32
+     * @return string An HTML representation of the opening form tag
  33
+     */
  34
+    public function form($url, array $attributes = array())
  35
+    {
  36
+        return sprintf('<form%s>', $this->generator->attributes(array_merge(array(
  37
+            'action' => $url,
  38
+            'method' => isset($attributes['method']) ? strtolower($attributes['method']) : 'post',
  39
+            'enctype' => $this->field->isMultipart() ? 'multipart/form-data' : null,
  40
+        ), $attributes)));
  41
+    }
  42
+
  43
+    public function render($template = null)
  44
+    {
  45
+        if (null === $template) {
  46
+            $template = sprintf('FrameworkBundle:Form:group/%s/field_group.php', $this->theme);
  47
+        }
  48
+
  49
+        return $this->engine->render($template, array('group' => $this));
  50
+    }
  51
+
  52
+    public function hidden($template = null)
  53
+    {
  54
+        if (null === $template) {
  55
+            $template = 'FrameworkBundle:Form:hidden.php';
  56
+        }
  57
+
  58
+        return $this->engine->render($template, array(
  59
+            'group'  => $this,
  60
+            'hidden' => $this->wrapFields($this->field->getHiddenFields(true))
  61
+        ));
  62
+    }
  63
+
  64
+    public function errors($template = null)
  65
+    {
  66
+        if (null === $template) {
  67
+            $template = 'FrameworkBundle:Form:errors.php';
  68
+        }
  69
+
  70
+        return $this->engine->render($template, array(
  71
+            'group'  => $this,
  72
+            'errors' => $this->field->getErrors()
  73
+        ));
  74
+    }
  75
+}
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Form/FieldInterface.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,22 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating\Form;
  4
+
  5
+/*
  6
+ * This file is part of the Symfony framework.
  7
+ *
  8
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9
+ *
  10
+ * This source file is subject to the MIT license that is bundled
  11
+ * with this source code in the file LICENSE.
  12
+ */
  13
+
  14
+/**
  15
+ * 
  16
+ *
  17
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18
+ */
  19
+interface FieldInterface extends \IteratorAggregate, \ArrayAccess
  20
+{
  21
+    function render($template = null);
  22
+}
Txt src/Symfony/Bundle/FrameworkBundle/Templating/Form/Form.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,44 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating\Form;
  4
+
  5
+use Symfony\Component\Templating\Helper\Helper;
  6
+use Symfony\Component\Templating\Engine;
  7
+use Symfony\Component\Form\FieldGroupInterface;
  8
+use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;
  9
+
  10
+/*
  11
+ * This file is part of the Symfony framework.
  12
+ *
  13
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  14
+ *
  15
+ * This source file is subject to the MIT license that is bundled
  16
+ * with this source code in the file LICENSE.
  17
+ */
  18
+
  19
+/**
  20
+ * Form is a factory that wraps Form instances.
  21
+ *
  22
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  23
+ */
  24
+class Form
  25
+{
  26
+    public $generator;
  27
+
  28
+    protected $engine;
  29
+    protected $theme;
  30
+    protected $doctype;
  31
+
  32
+    public function __construct(Engine $engine, HtmlGeneratorInterface $generator, $theme = 'table', $doctype = 'xhtml')
  33
+    {
  34
+        $this->engine = $engine;
  35
+        $this->generator = $generator;
  36
+        $this->theme = $theme;
  37
+        $this->doctype = $doctype;
  38
+    }
  39
+
  40
+    public function get(FieldGroupInterface $group, $theme = null, $doctype = null)
  41
+    {
  42
+        return new FieldGroup($group, $this->engine, $this->generator, null === $theme ? $this->theme : $theme, null === $doctype ? $this->doctype : $doctype);
  43
+    }
  44
+}
Txt src/Symfony/Component/Form/HtmlGenerator.php → src/Symfony/Bundle/FrameworkBundle/Templating/HtmlGenerator.php
  • View file @ 4027f75
... ...
@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3  
-namespace Symfony\Component\Form;
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating;
4 4
 
5 5
 /**
6 6
  * An implementation of HtmlGeneratorInterface
... ...
@@ -96,6 +96,52 @@ class HtmlGenerator implements HtmlGeneratorInterface
96 96
         return implode('', array_map(array($this, 'attributesCallback'), array_keys($attributes), array_values($attributes)));
97 97
     }
98 98
 
  99
+    public function choices(array $preferredChoices, array $choices, $empty, array $selected)
  100
+    {
  101
+        $html = '';
  102
+
  103
+        if (false !== $empty) {
  104
+            $html .= $this->doChoices(array('' => $empty), $selected)."\n";
  105
+        }
  106
+
  107
+        if (count($preferredChoices) > 0) {
  108
+            $html .= $this->doChoices($preferredChoices, $selected)."\n";
  109
+            $html .= $this->contentTag('option', $origin->getOption('separator'), array('disabled' => true))."\n";
  110
+        }
  111
+
  112
+        $html .= $this->doChoices($choices, $selected)."\n";
  113
+
  114
+        return $html;
  115
+    }
  116
+
  117
+    protected function doChoices(array $choices, array $selected)
  118
+    {
  119
+        $options = array();
  120
+        foreach ($choices as $key => $option) {
  121
+            if (is_array($option)) {
  122
+                $options[] = $this->contentTag(
  123
+                    'optgroup',
  124
+                    "\n".renderChoices($option, $selected)."\n",
  125
+                    array('label' => $this->escape($key))
  126
+                );
  127
+            } else {
  128
+                $attributes = array('value' => $this->escape($key));
  129
+
  130
+                if (isset($selected[strval($key)])) {
  131
+                    $attributes['selected'] = true;
  132
+                }
  133
+
  134
+                $options[] = $this->contentTag(
  135
+                    'option',
  136
+                    $this->escape($option),
  137
+                    $attributes
  138
+                );
  139
+            }
  140
+        }
  141
+
  142
+        return implode("\n", $options);
  143
+    }
  144
+
99 145
     /**
100 146
      * Prepares an attribute key and value for HTML representation.
101 147
      *
Txt src/Symfony/Component/Form/HtmlGeneratorInterface.php → src/Symfony/Bundle/FrameworkBundle/Templating/HtmlGeneratorInterface.php
  • View file @ 4027f75
... ...
@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3  
-namespace Symfony\Component\Form;
  3
+namespace Symfony\Bundle\FrameworkBundle\Templating;
4 4
 
5 5
 /**
6 6
  * Marks classes able to generate HTML code
Txt src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
  • View file @ 4027f75
... ...
@@ -36,6 +36,17 @@ class TwigExtension extends Extension
36 36
         }
37 37
 
38 38
         $container->setParameter('twig.options', array_replace($container->getParameter('twig.options'), $config));
  39
+
  40
+        // form resources
  41
+        foreach (array('resources', 'resource') as $key) {
  42
+            if (isset($config['form'][$key])) {
  43
+                $resources = $config['form'][$key];
  44
+                if (!is_array($resources)) {
  45
+                    $resources = array($resources);
  46
+                }
  47
+                $container->setParameter('twig.form.resources', array_merge($container->getParameter('twig.form.resources'), $resources));
  48
+            }
  49
+        }
39 50
     }
40 51
 
41 52
     /**
Txt src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,240 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\Extension;
  4
+
  5
+use Symfony\Component\Form\Form;
  6
+use Symfony\Component\Form\FieldGroupInterface;
  7
+use Symfony\Component\Form\FieldInterface;
  8
+use Symfony\Bundle\TwigBundle\TokenParser\FormThemeTokenParser;
  9
+use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;
  10
+
  11
+/*
  12
+ * This file is part of the Symfony package.
  13
+ *
  14
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  15
+ *
  16
+ * For the full copyright and license information, please view the LICENSE
  17
+ * file that was distributed with this source code.
  18
+ */
  19
+
  20
+/**
  21
+ *
  22
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  23
+ */
  24
+class FormExtension extends \Twig_Extension
  25
+{
  26
+    static protected $cache = array();
  27
+
  28
+    protected $resources;
  29
+    protected $templates;
  30
+    protected $environment;
  31
+    protected $themes;
  32
+    protected $generator;
  33
+
  34
+    public function __construct(HtmlGeneratorInterface $generator, array $resources = array())
  35
+    {
  36
+        $this->generator = $generator;
  37
+        $this->themes = new \SplObjectStorage();
  38
+        $this->resources = array_merge(array(
  39
+            'TwigBundle::form.twig',
  40
+            'TwigBundle::widgets.twig',
  41
+        ), $resources);
  42
+    }
  43
+
  44
+    /**
  45
+     * {@inheritdoc}
  46
+     */
  47
+    public function initRuntime(\Twig_Environment $environment)
  48
+    {
  49
+        $this->environment = $environment;
  50
+
  51
+        $this->templates = $this->resolveResources($this->resources);
  52
+    }
  53
+
  54
+    public function setTheme(FieldGroupInterface $group, array $resources)
  55
+    {
  56
+        $this->themes->attach($group, $resources);
  57
+    }
  58
+
  59
+    /**
  60
+     * Returns the token parser instance to add to the existing list.
  61
+     *
  62
+     * @return array An array of Twig_TokenParser instances
  63
+     */
  64
+    public function getTokenParsers()
  65
+    {
  66
+        return array(
  67
+            // {% form_theme form "SomeBungle::widgets.twig" %}
  68
+            new FormThemeTokenParser(),
  69
+        );
  70
+    }
  71
+
  72
+    /**
  73
+     * {@inheritdoc}
  74
+     */
  75
+    public function getFilters()
  76
+    {
  77
+        return array(
  78
+            'render_enctype' => new \Twig_Filter_Method($this, 'renderEnctype', array('is_escaper' => true)),
  79
+            'render'         => new \Twig_Filter_Method($this, 'render', array('is_escaper' => true)),
  80
+            'render_hidden'  => new \Twig_Filter_Method($this, 'renderHidden', array('is_escaper' => true)),
  81
+            'render_errors'  => new \Twig_Filter_Method($this, 'renderErrors', array('is_escaper' => true)),
  82
+            'render_widget'  => new \Twig_Filter_Method($this, 'renderWidget', array('is_escaper' => true)),
  83
+            'render_label'   => new \Twig_Filter_Method($this, 'renderLabel', array('is_escaper' => true)),
  84
+            'render_data'    => new \Twig_Filter_Method($this, 'renderData', array('is_escaper' => true)),
  85
+            'render_choices' => new \Twig_Filter_Method($this, 'renderChoices', array('is_escaper' => true)),
  86
+        );
  87
+    }
  88
+
  89
+    public function renderEnctype(Form $form)
  90
+    {
  91
+        return $form->isMultipart() ? 'enctype="multipart/form-data"' : '';
  92
+    }
  93
+
  94
+    public function render(FieldInterface $field, array $attributes = array())
  95
+    {
  96
+        if ($field instanceof Form || get_class($field) === 'Symfony\Component\Form\FieldGroup') {
  97
+            return $this->templates['group']->getBlock('group', array(
  98
+                'group'      => $field,
  99
+                'attributes' => $attributes,
  100
+            ));
  101
+        }
  102
+
  103
+        return $this->templates['field']->getBlock('field', array(
  104
+            'field'      => $field,
  105
+            'attributes' => $attributes,
  106
+        ));
  107
+    }
  108
+
  109
+    public function renderHidden(FieldGroupInterface $form)
  110
+    {
  111
+        return $this->templates['hidden']->getBlock('hidden', array(
  112
+            'fields' => $form->getHiddenFields()
  113
+        ));
  114
+    }
  115
+
  116
+    public function renderErrors($formOrField)
  117
+    {
  118
+        return $this->templates['errors']->getBlock('errors', array(
  119
+            'errors' => $formOrField->getErrors()
  120
+        ));
  121
+    }
  122
+
  123
+    public function renderLabel(FieldInterface $field, $label = null, array $attributes = array())
  124
+    {
  125
+        return $this->templates['label']->getBlock('label', array(
  126
+            'id'         => $field->getId(),
  127
+            'key'        => $field->getKey(),
  128
+            'label'      => null !== $label ? $label : ucfirst(strtolower(str_replace('_', ' ', $field->getKey()))),
  129
+            'attributes' => $attributes,
  130
+        ));
  131
+    }
  132
+
  133
+    public function renderWidget(FieldInterface $field, array $attributes = array(), $resources = null)
  134
+    {
  135
+        if (null === $resources) {
  136
+            $parent = $field;
  137
+            $resources = array();
  138
+            while ($parent = $parent->getParent()) {
  139
+                if (isset($this->themes[$parent])) {
  140
+                    $resources = $this->themes[$parent];
  141
+                }
  142
+            }
  143
+        } else {
  144
+            $resources = array($resources);
  145
+        }
  146
+
  147
+        list($widget, $template) = $this->getWidget($field, $resources);
  148
+
  149
+        return $template->getBlock($widget, array(
  150
+            'field'      => $field,
  151
+            'attributes' => array_merge($field->getAttributes(), $attributes),
  152
+        ));
  153
+    }
  154
+
  155
+    public function renderData(FieldInterface $field)
  156
+    {
  157
+        return $field->getData();
  158
+    }
  159
+
  160
+    public function renderChoices(FieldInterface $field)
  161
+    {
  162
+        return $this->generator->choices(
  163
+            $field->getPreferredChoices(),
  164
+            $field->getOtherChoices(),
  165
+            $field->getEmptyValue(),
  166
+            $field->getSelected()
  167
+        );
  168
+    }
  169
+
  170
+    protected function getWidget(FieldInterface $field, array $resources = array())
  171
+    {
  172
+        $cacheable = true;
  173
+        $templates = array();
  174
+        if ($resources) {
  175
+            $templates = $this->resolveResources($resources);
  176
+            $cacheable = false;
  177
+        }
  178
+
  179
+        // add "global" templates as fallback
  180
+        $templates = array_merge($this->templates, $templates);
  181
+
  182
+        $class = get_class($field);
  183
+
  184
+        if (true === $cacheable && isset(self::$cache[$class])) {
  185
+            return self::$cache[$class];
  186
+        }
  187
+
  188
+        // find a template for the given class or one of its parents
  189
+        do {
  190
+            $parts = explode('\\', $class);
  191
+            $c = array_pop($parts);
  192
+
  193
+            $underscore = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($c, '_', '.')));
  194
+
  195
+            if (isset($templates[$underscore])) {
  196
+                if (true === $cacheable) {
  197
+                    self::$cache[$class] = array($underscore, $templates[$underscore]);
  198
+                }
  199
+
  200
+                return array($underscore, $templates[$underscore]);
  201
+            }
  202
+        } while (false !== $class = get_parent_class($class));
  203
+
  204
+        throw new \RuntimeException(sprintf('Unable to render the "%s" field.', $field->getKey()));
  205
+    }
  206
+
  207
+    protected function resolveResources(array $resources)
  208
+    {
  209
+        $templates = array();
  210
+        foreach ($resources as $resource)
  211
+        {
  212
+            $blocks = $this->resolveTemplate($this->environment->loadTemplate($resource));
  213
+
  214
+            $templates = array_replace($templates, $blocks);
  215
+        }
  216
+
  217
+        return $templates;
  218
+    }
  219
+
  220
+    protected function resolveTemplate($template)
  221
+    {
  222
+        // an array of blockName => template
  223
+        $blocks = array();
  224
+        foreach ($template->getBlockNames() as $name) {
  225
+            $blocks[$name] = $template;
  226
+        }
  227
+
  228
+        return $blocks;
  229
+    }
  230
+
  231
+    /**
  232
+     * Returns the name of the extension.
  233
+     *
  234
+     * @return string The extension name
  235
+     */
  236
+    public function getName()
  237
+    {
  238
+        return 'form';
  239
+    }
  240
+}
Txt src/Symfony/Bundle/TwigBundle/Extension/HtmlExtension.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,62 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\Extension;
  4
+
  5
+use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;
  6
+use Symfony\Bundle\TwigBundle\TokenParser\TagTokenParser;
  7
+use Symfony\Bundle\TwigBundle\TokenParser\ContentTagTokenParser;
  8
+use Symfony\Bundle\TwigBundle\TokenParser\ChoiceTagTokenParser;
  9
+
  10
+/*
  11
+ * This file is part of the Symfony package.
  12
+ *
  13
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  14
+ *
  15
+ * For the full copyright and license information, please view the LICENSE
  16
+ * file that was distributed with this source code.
  17
+ */
  18
+
  19
+/**
  20
+ *
  21
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  22
+ */
  23
+class HtmlExtension extends \Twig_Extension
  24
+{
  25
+    protected $generator;
  26
+
  27
+    public function __construct(HtmlGeneratorInterface $generator)
  28
+    {
  29
+        $this->generator = $generator;
  30
+    }
  31
+
  32
+    public function getGenerator()
  33
+    {
  34
+        return $this->generator;
  35
+    }
  36
+
  37
+    /**
  38
+     * Returns the token parser instance to add to the existing list.
  39
+     *
  40
+     * @return array An array of Twig_TokenParser instances
  41
+     */
  42
+    public function getTokenParsers()
  43
+    {
  44
+        return array(
  45
+            // {% tag "input" with attributes %}
  46
+            new TagTokenParser(),
  47
+
  48
+            // {% contenttag "textarea" with attributes %}content{% endcontenttag %}
  49
+            new ContentTagTokenParser(),
  50
+        );
  51
+    }
  52
+
  53
+    /**
  54
+     * Returns the name of the extension.
  55
+     *
  56
+     * @return string The extension name
  57
+     */
  58
+    public function getName()
  59
+    {
  60
+        return 'html';
  61
+    }
  62
+}
Txt src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,49 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\Node;
  4
+
  5
+/*
  6
+ * This file is part of the Symfony package.
  7
+ *
  8
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9
+ *
  10
+ * For the full copyright and license information, please view the LICENSE
  11
+ * file that was distributed with this source code.
  12
+ */
  13
+
  14
+/**
  15
+ * 
  16
+ *
  17
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18
+ */
  19
+class FormThemeNode extends \Twig_Node
  20
+{
  21
+    public function __construct(\Twig_NodeInterface $form, \Twig_NodeInterface $resources, $lineno, $tag = null)
  22
+    {
  23
+        parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
  24
+    }
  25
+
  26
+    /**
  27
+     * Compiles the node to PHP.
  28
+     *
  29
+     * @param \Twig_Compiler A Twig_Compiler instance
  30
+     */
  31
+    public function compile($compiler)
  32
+    {
  33
+        $compiler
  34
+            ->addDebugInfo($this)
  35
+            ->write('echo $this->env->getExtension(\'form\')->setTheme(')
  36
+            ->subcompile($this->getNode('form'))
  37
+            ->raw(', array(')
  38
+        ;
  39
+
  40
+        foreach ($this->getNode('resources') as $resource) {
  41
+            $compiler
  42
+                ->subcompile($resource)
  43
+                ->raw(', ')
  44
+            ;
  45
+        }
  46
+
  47
+        $compiler->raw('));');
  48
+    }
  49
+}
Txt src/Symfony/Bundle/TwigBundle/Node/HelperNode.php
  • View file @ 4027f75
... ...
@@ -35,15 +35,15 @@ class HelperNode extends \Twig_Node
35 35
             ->raw("\$this->env->getExtension(")
36 36
             ->string('symfony.helpers')
37 37
             ->raw(")->getContainer()->get(")
38  
-            ->string($this['helper'])
  38
+            ->string($this->getAttribute('helper'))
39 39
             ->raw(")->")
40  
-            ->raw($this['method'])
  40
+            ->raw($this->getAttribute('method'))
41 41
             ->raw("(")
42 42
         ;
43 43
 
44  
-        foreach ($this->values as $i => $value) {
  44
+        foreach ($this->getNode('values') as $i => $value) {
45 45
             $compiler->subcompile($value);
46  
-            if ($i !== count($this->values) - 1) {
  46
+            if ($i !== count($this->getNode('values')) - 1) {
47 47
                 $compiler->raw(', ');
48 48
             }
49 49
         }
Txt src/Symfony/Bundle/TwigBundle/Node/TagNode.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,62 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\Node;
  4
+
  5
+/*
  6
+ * This file is part of the Symfony package.
  7
+ *
  8
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9
+ *
  10
+ * For the full copyright and license information, please view the LICENSE
  11
+ * file that was distributed with this source code.
  12
+ */
  13
+
  14
+/**
  15
+ * 
  16
+ *
  17
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18
+ */
  19
+class TagNode extends \Twig_Node
  20
+{
  21
+    public function __construct(\Twig_NodeInterface $htmlTag, \Twig_NodeInterface $content = null, \Twig_Node_Expression $attributes = null, $lineno, $tag = null)
  22
+    {
  23
+        parent::__construct(array('html_tag' => $htmlTag, 'content' => $content, 'html_attributes' => $attributes), array(), $lineno, $tag);
  24
+    }
  25
+
  26
+    /**
  27
+     * Compiles the node to PHP.
  28
+     *
  29
+     * @param \Twig_Compiler A Twig_Compiler instance
  30
+     */
  31
+    public function compile($compiler)
  32
+    {
  33
+        $compiler->addDebugInfo($this);
  34
+
  35
+        $method = null === $this->getNode('content') ? 'tag' : 'contentTag';
  36
+
  37
+        if (null !== $this->getNode('content')) {
  38
+            $compiler
  39
+                ->write("ob_start();\n")
  40
+                ->subcompile($this->getNode('content'))
  41
+                ->write('$content = ob_get_clean();')
  42
+            ;
  43
+        }
  44
+
  45
+        $compiler
  46
+            ->write('echo $this->env->getExtension(\'html\')->getGenerator()->'.$method.'(')
  47
+            ->subcompile($this->getNode('html_tag'))
  48
+            ->raw(', ')
  49
+        ;
  50
+
  51
+        if (null !== $this->getNode('content')) {
  52
+            $compiler
  53
+                ->raw('$content, ')
  54
+            ;
  55
+        }
  56
+
  57
+        $compiler
  58
+            ->subcompile($this->getNode('html_attributes'))
  59
+            ->raw(');')
  60
+        ;
  61
+    }
  62
+}
Txt src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd
  • View file @ 4027f75
... ...
@@ -5,14 +5,24 @@
5 5
     targetNamespace="http://www.symfony-project.org/schema/dic/twig"
6 6
     elementFormDefault="qualified">
7 7
 
8  
-  <xsd:element name="config" type="config" />
  8
+    <xsd:element name="config" type="config" />
9 9
 
10  
-  <xsd:complexType name="config">
11  
-    <xsd:attribute name="charset" type="xsd:string" />
12  
-    <xsd:attribute name="debug" type="xsd:string" />
13  
-    <xsd:attribute name="cache" type="xsd:string" />
14  
-    <xsd:attribute name="trim_blocks" type="xsd:string" />
15  
-    <xsd:attribute name="auto_reload" type="xsd:string" />
16  
-    <xsd:attribute name="base_template_class" type="xsd:string" />
17  
-  </xsd:complexType>
  10
+    <xsd:complexType name="config">
  11
+        <xsd:sequence>
  12
+            <xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
  13
+        </xsd:sequence>
  14
+
  15
+        <xsd:attribute name="charset" type="xsd:string" />
  16
+        <xsd:attribute name="debug" type="xsd:string" />
  17
+        <xsd:attribute name="cache" type="xsd:string" />
  18
+        <xsd:attribute name="trim_blocks" type="xsd:string" />
  19
+        <xsd:attribute name="auto_reload" type="xsd:string" />
  20
+        <xsd:attribute name="base_template_class" type="xsd:string" />
  21
+    </xsd:complexType>
  22
+
  23
+    <xsd:complexType name="form">
  24
+        <xsd:sequence>
  25
+            <xsd:element name="resource" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
  26
+        </xsd:sequence>
  27
+    </xsd:complexType>
18 28
 </xsd:schema>
Txt src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
  • View file @ 4027f75
... ...
@@ -13,6 +13,7 @@
13 13
         </parameter>
14 14
         <parameter key="twig.loader.class">Symfony\Bundle\TwigBundle\Loader\Loader</parameter>
15 15
         <parameter key="twig.renderer.class">Symfony\Bundle\TwigBundle\Renderer\Renderer</parameter>
  16
+        <parameter key="twig.form.resources" type="collection"></parameter>
16 17
     </parameters>
17 18
 
18 19
     <services>
... ...
@@ -42,9 +43,20 @@
42 43
             <argument type="service" id="translator" />
43 44
         </service>
44 45
 
  46
+        <service id="twig.extension.html" class="Symfony\Bundle\TwigBundle\Extension\HtmlExtension">
  47
+            <tag name="twig.extension" />
  48
+            <argument type="service" id="templating.html.generator" />
  49
+        </service>
  50
+
45 51
         <service id="twig.extension.helpers" class="Symfony\Bundle\TwigBundle\Extension\HelpersExtension">
46 52
             <tag name="twig.extension" />
47 53
             <argument type="service" id="service_container" />
48 54
         </service>
  55
+
  56
+        <service id="twig.extension.form" class="Symfony\Bundle\TwigBundle\Extension\FormExtension">
  57
+            <tag name="twig.extension" />
  58
+            <argument type="service" id="templating.html.generator" />
  59
+            <argument>%twig.form.resources%</argument>
  60
+        </service>
49 61
     </services>
50 62
 </container>
Txt src/Symfony/Bundle/TwigBundle/Resources/views/form.twig
  • View file @ 4027f75
... ...
@@ -0,0 +1,41 @@
  1
+{% block group %}
  2
+    {{ group|render_errors }}
  3
+    <table>
  4
+        {% for field in group %}
  5
+            {% if not field.ishidden %}
  6
+                {{ field|render }}
  7
+            {% endif %}
  8
+        {% endfor %}
  9
+    </table>
  10
+    {{ group|render_hidden }}
  11
+{% endblock group %}
  12
+
  13
+{% block field %}
  14
+    <tr>
  15
+        <th>{{ field|render_label }}</th>
  16
+        <td>
  17
+            {{ field|render_errors }}
  18
+            {{ field|render_widget }}
  19
+        </td>
  20
+    </tr>
  21
+{% endblock field %}
  22
+
  23
+{% block errors %}
  24
+    {% if errors %}
  25
+    <ul>
  26
+        {% for error in errors %}
  27
+            <li>{% trans error.0 with error.1 from validators %}</li>
  28
+        {% endfor %}
  29
+    </ul>
  30
+    {% endif %}
  31
+{% endblock errors %}
  32
+
  33
+{% block hidden %}
  34
+    {% for field in fields %}
  35
+        {{ field|render_widget }}
  36
+    {% endfor %}
  37
+{% endblock hidden %}
  38
+
  39
+{% block label %}
  40
+    <label for="{{ id }}">{% trans label %}</label>
  41
+{% endblock label %}
Txt src/Symfony/Bundle/TwigBundle/Resources/views/widgets.twig
  • View file @ 4027f75
... ...
@@ -0,0 +1,57 @@
  1
+{% block input_field %}
  2
+    {% tag "input" with attributes %}
  3
+{% endblock input_field %}
  4
+
  5
+{% block textarea_field %}
  6
+    {% contenttag "textarea" with attributes %}{{ field.displayedData }}{% endcontenttag %}
  7
+{% endblock textarea_field %}
  8
+
  9
+{% block choice_field %}
  10
+    {% if field.options.expanded %}
  11
+        {% for child in field %}
  12
+            {{ child|render_widget }}
  13
+        {% endfor %}
  14
+    {% else %}
  15
+        {% contenttag "select" with attributes %}
  16
+            {{ field|render_choices }}
  17
+        {% endcontenttag %}
  18
+    {% endif %}
  19
+{% endblock choice_field %}
  20
+
  21
+{% block toggle_field %}
  22
+    {% display input_field %}
  23
+    {% if field.options.label %}
  24
+        {% contenttag "label" with ['for': field.id] %}{% trans field.options.label %}{% endcontenttag %}
  25
+    {% endif %}
  26
+{% endblock toggle_field %}
  27
+
  28
+{% block date_time_field %}
  29
+    {{ field.date|render_widget }}
  30
+    {{ field.time|render_widget }}
  31
+{% endblock date_time_field %}
  32
+
  33
+{% block date_field %}
  34
+    {% if field.field %}
  35
+        {% display input_field %}
  36
+    {% else %}
  37
+        {{ field.pattern|replace(['{{ year }}': field.year|render_widget, '{{ month }}': field.month|render_widget, '{{ day }}': field.day|render_widget,]) }}
  38
+    {% endif %}
  39
+{% endblock date_field %}
  40
+
  41
+{% block time_field %}
  42
+    {% if field.isfield %}
  43
+        {% display input_field %}
  44
+    {% else %}
  45
+        {{ field.hour|render_widget }}:{{ field.minute|render_widget }}
  46
+        {% if field.options.with_seconds %}:{{ field.second|render_widget }}{% endif %}
  47
+    {% endif %}
  48
+{% endblock time_field %}
  49
+
  50
+{% block money_field %}
  51
+    {% set widget %}{% display input_field %}{% endset %}
  52
+    {{ field.pattern|replace(['{{ widget }}': widget]) }}
  53
+{% endblock money_field %}
  54
+
  55
+{% block percent_field %}
  56
+    {% display input_field %} %
  57
+{% endblock percent_field %}
Txt src/Symfony/Bundle/TwigBundle/TokenParser/ContentTagTokenParser.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,66 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\TokenParser;
  4
+
  5
+use Symfony\Bundle\TwigBundle\Node\TagNode;
  6
+
  7
+/*
  8
+ * This file is part of the Symfony package.
  9
+ *
  10
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  11
+ *
  12
+ * For the full copyright and license information, please view the LICENSE
  13
+ * file that was distributed with this source code.
  14
+ */
  15
+
  16
+/**
  17
+ * 
  18
+ *
  19
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20
+ */
  21
+class ContentTagTokenParser extends \Twig_TokenParser
  22
+{
  23
+    /**
  24
+     * Parses a token and returns a node.
  25
+     *
  26
+     * @param  \Twig_Token $token A Twig_Token instance
  27
+     *
  28
+     * @return \Twig_NodeInterface A Twig_NodeInterface instance
  29
+     */
  30
+    public function parse(\Twig_Token $token)
  31
+    {
  32
+        $lineno = $token->getLine();
  33
+        $stream = $this->parser->getStream();
  34
+
  35
+        $tag = $this->parser->getExpressionParser()->parseExpression();
  36
+
  37
+        $attributes = null;
  38
+        if ($stream->test('with')) {
  39
+            $stream->next();
  40
+            $attributes = $this->parser->getExpressionParser()->parseExpression();
  41
+        }
  42
+
  43
+        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  44
+
  45
+        $content = $this->parser->subparse(array($this, 'decideContentTagFork'), true);
  46
+
  47
+        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  48
+
  49
+        return new TagNode($tag, $content, $attributes, $lineno, $this->getTag());
  50
+    }
  51
+
  52
+    public function decideContentTagFork($token)
  53
+    {
  54
+        return $token->test(array('endcontenttag'));
  55
+    }
  56
+
  57
+    /**
  58
+     * Gets the tag name associated with this token parser.
  59
+     *
  60
+     * @param string The tag name
  61
+     */
  62
+    public function getTag()
  63
+    {
  64
+        return 'contenttag';
  65
+    }
  66
+}
Txt src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,55 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\TokenParser;
  4
+
  5
+use Symfony\Bundle\TwigBundle\Node\FormThemeNode;
  6
+
  7
+/*
  8
+ * This file is part of the Symfony package.
  9
+ *
  10
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  11
+ *
  12
+ * For the full copyright and license information, please view the LICENSE
  13
+ * file that was distributed with this source code.
  14
+ */
  15
+
  16
+/**
  17
+ * 
  18
+ *
  19
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20
+ */
  21
+class FormThemeTokenParser extends \Twig_TokenParser
  22
+{
  23
+    /**
  24
+     * Parses a token and returns a node.
  25
+     *
  26
+     * @param  \Twig_Token $token A Twig_Token instance
  27
+     *
  28
+     * @return \Twig_NodeInterface A Twig_NodeInterface instance
  29
+     */
  30
+    public function parse(\Twig_Token $token)
  31
+    {
  32
+        $lineno = $token->getLine();
  33
+        $stream = $this->parser->getStream();
  34
+
  35
+        $form = $this->parser->getExpressionParser()->parseExpression();
  36
+        $resources = array();
  37
+        do {
  38
+            $resources[] = $this->parser->getExpressionParser()->parseExpression();
  39
+        } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
  40
+
  41
+        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  42
+
  43
+        return new FormThemeNode($form, new \Twig_Node($resources), $lineno, $this->getTag());
  44
+    }
  45
+
  46
+    /**
  47
+     * Gets the tag name associated with this token parser.
  48
+     *
  49
+     * @param string The tag name
  50
+     */
  51
+    public function getTag()
  52
+    {
  53
+        return 'form_theme';
  54
+    }
  55
+}
Txt src/Symfony/Bundle/TwigBundle/TokenParser/TagTokenParser.php
  • View file @ 4027f75
... ...
@@ -0,0 +1,57 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Bundle\TwigBundle\TokenParser;
  4
+
  5
+use Symfony\Bundle\TwigBundle\Node\TagNode;
  6
+
  7
+/*
  8
+ * This file is part of the Symfony package.
  9
+ *
  10
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  11
+ *
  12
+ * For the full copyright and license information, please view the LICENSE
  13
+ * file that was distributed with this source code.
  14
+ */
  15
+
  16
+/**
  17
+ * 
  18
+ *
  19
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  20
+ */
  21
+class TagTokenParser extends \Twig_TokenParser
  22
+{
  23
+    /**
  24
+     * Parses a token and returns a node.
  25
+     *
  26
+     * @param  \Twig_Token $token A Twig_Token instance
  27
+     *
  28
+     * @return \Twig_NodeInterface A Twig_NodeInterface instance
  29
+     */
  30
+    public function parse(\Twig_Token $token)
  31
+    {
  32
+        $lineno = $token->getLine();
  33
+        $stream = $this->parser->getStream();
  34
+
  35
+        $tag = $this->parser->getExpressionParser()->parseExpression();
  36
+
  37
+        $attributes = null;
  38
+        if ($stream->test('with')) {
  39
+            $stream->next();
  40
+            $attributes = $this->parser->getExpressionParser()->parseExpression();
  41
+        }
  42
+
  43
+        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  44
+
  45
+        return new TagNode($tag, null, $attributes, $lineno, $this->getTag());
  46
+    }
  47
+
  48
+    /**
  49
+     * Gets the tag name associated with this token parser.
  50
+     *
  51
+     * @param string The tag name
  52
+     */
  53
+    public function getTag()
  54
+    {
  55
+        return 'tag';
  56
+    }
  57
+}
Txt src/Symfony/Component/Form/CheckboxField.php
  • View file @ 4027f75
... ...
@@ -21,10 +21,10 @@ class CheckboxField extends ToggleField
21 21
     /**
22 22
      * {@inheritDoc}
23 23
      */
24  
-    public function render(array $attributes = array())
  24
+    public function getAttributes()
25 25
     {
26  
-        return parent::render(array_merge(array(
  26
+        return array_merge(parent::getAttributes(), array(
27 27
             'type' => 'checkbox',
28  
-        ), $attributes));
  28
+        ));
29 29
     }
30 30
 }
31 31
\ No newline at end of file
Txt src/Symfony/Component/Form/ChoiceField.php
  • View file @ 4027f75
... ...
@@ -37,7 +37,6 @@ class ChoiceField extends HybridField
37 37
         $this->addOption('multiple', false);
38 38
         $this->addOption('expanded', false);
39 39
         $this->addOption('empty_value', '');
40  
-        $this->addOption('translate_choices', false);
41 40
 
42 41
         if (!is_array($this->getOption('choices'))) {
43 42
             throw new UnexpectedTypeException('The choices option must be an array');
... ...
@@ -71,6 +70,51 @@ class ChoiceField extends HybridField
71 70
     }
72 71
 
73 72
     /**
  73
+     * {@inheritDoc}
  74
+     */
  75
+    public function getAttributes()
  76
+    {
  77
+        $attributes = array(
  78
+            'id'       => $this->getId(),
  79
+            'name'     => $this->getName(),
  80
+            'disabled' => $this->isDisabled(),
  81
+        );
  82
+
  83
+        // Add "[]" to the name in case a select tag with multiple options is
  84
+        // displayed. Otherwise only one of the selected options is sent in the
  85
+        // POST request.
  86
+        if ($this->getOption('multiple') && !$this->getOption('expanded')) {
  87
+            $attributes['name'] .= '[]';
  88
+        }
  89
+
  90
+        if ($this->getOption('multiple')) {
  91
+            $attributes['multiple'] = 'multiple';
  92
+        }
  93
+
  94
+        return array_merge(parent::getAttributes(), $attributes);
  95
+    }
  96
+
  97
+    public function getSelected()
  98
+    {
  99
+        return array_flip(array_map('strval', (array) $this->getDisplayedData()));
  100
+    }
  101
+
  102
+    public function getPreferredChoices()
  103
+    {
  104
+        return array_intersect_key($this->getOption('choices'), $this->preferredChoices);
  105
+    }
  106
+
  107
+    public function getOtherChoices()
  108
+    {
  109
+        return array_diff_key($this->getOption('choices'), $this->preferredChoices);
  110
+    }
  111
+
  112
+    public function getEmptyValue()
  113
+    {
  114
+        return $this->isRequired() ? false : $this->getOption('empty_value');
  115
+    }
  116
+
  117
+    /**
74 118
      * Returns a new field of type radio button or checkbox.
75 119
      *
76 120
      * @param string $key      The key for the option
... ...
@@ -82,13 +126,11 @@ class ChoiceField extends HybridField
82 126
             return new CheckboxField($choice, array(
83 127
                 'value' => $choice,
84 128
                 'label' => $label,
85  
-                'translate_label' => $this->getOption('translate_choices'),
86 129
             ));
87 130
         } else {
88 131
             return new RadioField($choice, array(
89 132
                 'value' => $choice,
90 133
                 'label' => $label,
91  
-                'translate_label' => $this->getOption('translate_choices'),
92 134
             ));
93 135
         }
94 136
     }
... ...
@@ -171,91 +213,4 @@ class ChoiceField extends HybridField
171 213
             return parent::reverseTransform($value);
172 214
         }
173 215
     }
174  
-
175  
-    /**
176  
-     * {@inheritDoc}
177  
-     */
178  
-    public function render(array $attributes = array())
179  
-    {
180  
-        if ($this->getOption('expanded')) {
181  
-            $html = "";
182  
-
183  
-            foreach ($this as $field) {
184  
-                $html .= $field->render()."\n";
185  
-            }
186  
-
187  
-            return $html;
188  
-        } else {
189  
-            $attrs['id'] = $this->getId();
190  
-            $attrs['name'] = $this->getName();
191  
-            $attrs['disabled'] = $this->isDisabled();
192  
-
193  
-            // Add "[]" to the name in case a select tag with multiple options is
194  
-            // displayed. Otherwise only one of the selected options is sent in the
195  
-            // POST request.
196  
-            if ($this->getOption('multiple') && !$this->getOption('expanded')) {
197  
-                $attrs['name'] .= '[]';
198  
-            }
199  
-
200  
-            if ($this->getOption('multiple')) {
201  
-                $attrs['multiple'] = 'multiple';
202  
-            }
203  
-
204  
-            $selected = array_flip(array_map('strval', (array)$this->getDisplayedData()));
205  
-            $html = "\n";
206  
-
207  
-            if (!$this->isRequired()) {
208  
-                $html .= $this->renderChoices(array('' => $this->getOption('empty_value')), $selected)."\n";
209  
-            }
210  
-
211  
-            $choices = $this->getOption('choices');
212  
-
213  
-            if (count($this->preferredChoices) > 0) {
214  
-                $html .= $this->renderChoices(array_intersect_key($choices, $this->preferredChoices), $selected)."\n";
215  
-                $html .= $this->generator->contentTag('option', $this->getOption('separator'), array('disabled' => true))."\n";
216  
-            }
217  
-
218  
-            $html .= $this->renderChoices(array_diff_key($choices, $this->preferredChoices), $selected)."\n";
219  
-
220  
-            return $this->generator->contentTag('select', $html, array_merge($attrs, $attributes));
221  
-        }
222  
-    }
223  
-
224  
-    /**
225  
-     * Returns an array of option tags for the choice field
226  
-     *
227  
-     * @return array  An array of option tags
228  
-     */
229  
-    protected function renderChoices(array $choices, array $selected)
230  
-    {
231  
-        $options = array();
232  
-
233  
-        foreach ($choices as $key => $option) {
234  
-            if (is_array($option)) {
235  
-                $options[] = $this->generator->contentTag(
236  
-                    'optgroup',
237  
-                    "\n".$this->renderChoices($option, $selected)."\n",
238  
-                    array('label' => $this->generator->escape($key))
239  
-                );
240  
-            } else {
241  
-                $attributes = array('value' => $this->generator->escape($key));
242  
-
243  
-                if (isset($selected[strval($key)])) {
244  
-                    $attributes['selected'] = true;
245  
-                }
246  
-
247  
-                if ($this->getOption('translate_choices')) {
248  
-                    $option = $this->translate($option);
249  
-                }
250  
-
251  
-                $options[] = $this->generator->contentTag(
252  
-                    'option',
253  
-                    $this->generator->escape($option),
254  
-                    $attributes
255  
-                );
256  
-            }
257  
-        }
258  
-
259  
-        return implode("\n", $options);
260  
-    }
261 216
 }
Txt src/Symfony/Component/Form/Configurable.php
  • View file @ 4027f75
... ...
@@ -143,4 +143,9 @@ abstract class Configurable
143 143
     {
144 144
         return isset($this->options[$name]);
145 145
     }
  146
+
  147
+    public function getOptions()
  148
+    {
  149
+        return $this->options;
  150
+    }
146 151
 }
Txt src/Symfony/Component/Form/DateField.php
  • View file @ 4027f75
... ...
@@ -79,7 +79,7 @@ class DateField extends HybridField
79 79
      *  * data_timezone:  The timezone of the data
80 80
      *  * user_timezone:  The timezone of the user entering a new value
81 81
      *  * pattern:        The pattern for the select boxes when "widget" is "select".
82  
-     *                    You can use the placeholders "%year%", "%month%" and "%day%".
  82
+     *                    You can use the placeholders "{{ year }}", "{{ month }}" and "{{ day }}".
83 83
      *                    Default: locale dependent
84 84
      *
85 85
      * @param array $options Options for this field
... ...
@@ -146,6 +146,23 @@ class DateField extends HybridField
146 146
     }
147 147
 
148 148
     /**
  149
+     * {@inheritDoc}
  150
+     */
  151
+    public function getAttributes()
  152
+    {
  153
+        if ($this->isField()) {
  154
+            return array_merge(parent::getAttributes(), array(
  155
+                'id'    => $this->getId(),
  156
+                'name'  => $this->getName(),
  157
+                'value' => $this->getDisplayedData(),
  158
+                'type'  => 'text',
  159
+            ));
  160
+        }
  161
+
  162
+        return parent::getAttributes();
  163
+    }
  164
+
  165
+    /**
149 166
      * Generates an array of choices for the given values
150 167
      *
151 168
      * If the values are shorter than $padLength characters, they are padded with
... ...
@@ -194,41 +211,22 @@ class DateField extends HybridField
194 211
         return $choices;
195 212
     }
196 213
 
197  
-    /**
198  
-     * {@inheritDoc}
199  
-     */
200  
-    public function render(array $attributes = array())
  214
+    public function getPattern()
201 215
     {
202  
-        if ($this->getOption('widget') === self::INPUT) {
203  
-            return $this->generator->tag('input', array_merge(array(
204  
-                'id'    => $this->getId(),
205  
-                'name'  => $this->getName(),
206  
-                'value' => $this->getDisplayedData(),
207  
-                'type'  => 'text',
208  
-            ), $attributes));
209  
-        } else {
210  
-            // set order as specified in the pattern
211  
-            if ($this->getOption('pattern')) {
212  
-                $pattern = $this->getOption('pattern');
213  
-            }
214  
-            // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
215  
-            // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
216  
-            else if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $this->formatter->getPattern())) {
217  
-                $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('%year%', '%month%', '%day%'), $this->formatter->getPattern());
218  
-            }
219  
-            // default fallback
220  
-            else {
221  
-                $pattern = '%year%-%month%-%day%';
222  
-            }
  216
+        // set order as specified in the pattern
  217
+        if ($this->getOption('pattern')) {
  218
+            return $this->getOption('pattern');
  219
+        }
223 220
 
224  
-            return str_replace(array('%year%', '%month%', '%day%'), array(
225  
-                $this->get('year')->render($attributes),
226  
-                $this->get('month')->render($attributes),
227  
-                $this->get('day')->render($attributes),
228  
-            ), $pattern);
  221
+        // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
  222
+        // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
  223
+        if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $this->formatter->getPattern())) {
  224
+            return preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $this->formatter->getPattern());
229 225
         }
230  
-    }
231 226
 
  227
+        // default fallback
  228
+        return '{{ year }}-{{ month }}-{{ day }}';
  229
+    }
232 230
 
233 231
     /**
234 232
      * Sets the locale of this field.
Txt src/Symfony/Component/Form/DateTimeField.php
  • View file @ 4027f75
... ...
@@ -120,15 +120,4 @@ class DateTimeField extends FieldGroup
120 120
     {
121 121
         return parent::reverseTransform(array_merge($value['date'], $value['time']));
122 122
     }
123  
-
124  
-    /**
125  
-     * {@inheritDoc}
126  
-     */
127  
-    public function render(array $attributes = array())
128  
-    {
129  
-        $html = $this->get('date')->render($attributes)."\n";
130  
-        $html .= $this->get('time')->render($attributes);
131  
-
132  
-        return $html;
133  
-    }
134 123
 }
Txt src/Symfony/Component/Form/Field.php
  • View file @ 4027f75
... ...
@@ -15,24 +15,15 @@ use Symfony\Component\Form\Exception\InvalidPropertyException;
15 15
 use Symfony\Component\Form\Exception\PropertyAccessDeniedException;
16 16
 use Symfony\Component\Form\ValueTransformer\ValueTransformerInterface;
17 17
 use Symfony\Component\Form\ValueTransformer\TransformationFailedException;
18  
-use Symfony\Component\I18N\TranslatorInterface;
19 18
 
20 19
 abstract class Field extends Configurable implements FieldInterface
21 20
 {
22  
-    /**
23  
-     * The object used for generating HTML code
24  
-     * @var HtmlGeneratorInterface
25  
-     */
26  
-    protected $generator = null;
27  
-
28 21
     protected $taintedData = null;
29 22
     protected $locale = null;
30  
-    protected $translator = null;
31 23
 
32 24
     private $errors = array();
33 25
     private $key = '';
34 26
     private $parent = null;
35  
-    private $renderer = null;
36 27
     private $bound = false;
37 28
     private $required = null;
38 29
     private $data = null;
... ...
@@ -48,7 +39,6 @@ abstract class Field extends Configurable implements FieldInterface
48 39
         $this->addOption('property_path', (string)$key);
49 40
 
50 41
         $this->key = (string)$key;
51  
-        $this->generator = new HtmlGenerator();
52 42
 
53 43
         if ($this->locale === null) {
54 44
             $this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en';
... ...
@@ -70,6 +60,11 @@ abstract class Field extends Configurable implements FieldInterface
70 60
         // TODO
71 61
     }
72 62
 
  63
+    public function getAttributes()
  64
+    {
  65
+        return array();
  66
+    }
  67
+
73 68
     /**
74 69
      * Returns the data of the field as it is displayed to the user.
75 70
      *
... ...
@@ -175,14 +170,6 @@ abstract class Field extends Configurable implements FieldInterface
175 170
     /**
176 171
      * {@inheritDoc}
177 172
      */
178  
-    public function setGenerator(HtmlGeneratorInterface $generator)
179  
-    {
180  
-        $this->generator = $generator;
181  
-    }
182  
-
183  
-    /**
184  
-     * {@inheritDoc}
185  
-     */
186 173
     public function isMultipart()
187 174
     {
188 175
         return false;
... ...
@@ -287,9 +274,9 @@ abstract class Field extends Configurable implements FieldInterface
287 274
      *
288 275
      * @see FieldInterface
289 276
      */
290  
-    public function addError($message, PropertyPath $path = null, $type = null)
  277
+    public function addError($messageTemplate, array $messageParameters = array(), PropertyPath $path = null, $type = null)
291 278
     {
292  
-        $this->errors[] = $message;
  279
+        $this->errors[] = array($messageTemplate, $messageParameters);
293 280
     }
294 281
 
295 282
     /**
... ...
@@ -347,55 +334,17 @@ abstract class Field extends Configurable implements FieldInterface
347 334
     }
348 335
 
349 336
     /**
350  
-     * Sets the translator of this field.
  337
+     * Injects the locale into the given object, if set.
351 338
      *
352  
-     * @see Translatable
353  
-     */
354  
-    public function setTranslator(TranslatorInterface $translator)
355  
-    {
356  
-        $this->translator = $translator;
357  
-
358  
-        if ($this->valueTransformer !== null && $this->valueTransformer instanceof Translatable) {
359  
-            $this->valueTransformer->setTranslator($translator);
360  
-        }
361  
-    }
362  
-
363  
-    /**
364  
-     * Translates the text using the associated translator, if available
365  
-     *
366  
-     * If no translator is available, the original text is returned without
367  
-     * modification.
368  
-     *
369  
-     * @param  string $text         The text to translate
370  
-     * @param  array $parameters    The parameters to insert in the text
371  
-     * @return string               The translated text
372  
-     */
373  
-    protected function translate($text, array $parameters = array())
374  
-    {
375  
-        if ($this->translator !== null) {
376  
-            $text = $this->translator->translate($text, $parameters);
377  
-        }
378  
-
379  
-        return $text;
380  
-    }
381  
-
382  
-    /**
383  
-     * Injects the locale and the translator into the given object, if set.
384  
-     *
385  
-     * The locale is injected only if the object implements Localizable. The
386  
-     * translator is injected only if the object implements Translatable.
  339
+     * The locale is injected only if the object implements Localizable.
387 340
      *
388 341
      * @param object $object
389 342
      */
390  
-    protected function injectLocaleAndTranslator($object)
  343
+    protected function injectLocale($object)
391 344
     {
392 345
         if ($object instanceof Localizable) {
393 346
             $object->setLocale($this->locale);
394 347
         }
395  
-
396  
-        if (!is_null($this->translator) && $object instanceof Translatable) {
397  
-            $object->setTranslator($this->translator);
398  
-        }
399 348
     }
400 349
 
401 350
     /**
... ...
@@ -405,7 +354,7 @@ abstract class Field extends Configurable implements FieldInterface
405 354
      */
406 355
     public function setValueTransformer(ValueTransformerInterface $valueTransformer)
407 356
     {
408  
-        $this->injectLocaleAndTranslator($valueTransformer);
  357
+        $this->injectLocale($valueTransformer);
409 358
 
410 359
         $this->valueTransformer = $valueTransformer;
411 360
     }
... ...
@@ -630,24 +579,4 @@ abstract class Field extends Configurable implements FieldInterface
630 579
             $objectOrArray[$propertyPath->getCurrent()] = $this->getData();
631 580
         }
632 581
     }
633  
-
634  
-    /**
635  
-     * {@inheritDoc}
636  
-     */
637  
-    public function renderErrors()
638  
-    {
639  
-        $html = '';
640  
-
641  
-        if ($this->hasErrors()) {
642  
-            $html .= "<ul>\n";
643  
-
644  
-            foreach ($this->getErrors() as $error) {
645  
-                $html .= "<li>" . $error . "</li>\n";
646  
-            }
647  
-
648  
-            $html .= "</ul>\n";
649  
-        }
650  
-
651  
-        return $html;
652  
-    }
653 582
 }
Txt src/Symfony/Component/Form/FieldGroup.php
  • View file @ 4027f75
... ...
@@ -13,10 +13,7 @@ namespace Symfony\Component\Form;
13 13
 
14 14
 use Symfony\Component\Form\Exception\AlreadyBoundException;
15 15
 use Symfony\Component\Form\Exception\UnexpectedTypeException;
16  
-use Symfony\Component\Form\Renderer\RendererInterface;
17  
-use Symfony\Component\Form\Renderer\TableRenderer;
18 16
 use Symfony\Component\Form\Iterator\RecursiveFieldsWithPropertyPathIterator;
19  
-use Symfony\Component\I18N\TranslatorInterface;
20 17
 
21 18
 /**
22 19
  * FieldGroup represents an array of widgets bind to names and values.
... ...
@@ -38,19 +35,6 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
38 35
     protected $extraFields = array();
39 36
 
40 37
     /**
41  
-     * Constructor
42  
-     *
43  
-     * @see FieldInterface::__construct()
44  
-     */
45  
-    public function __construct($key, array $options = array())
46  
-    {
47  
-        // set the default renderer before calling the configure() method
48  
-        $this->setRenderer(new TableRenderer());
49  
-
50  
-        parent::__construct($key, $options);
51  
-    }
52  
-
53  
-    /**
54 38
      * Clones this group
55 39
      */
56 40
     public function __clone()
... ...
@@ -109,11 +93,6 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
109 93
 
110 94
         $field->setParent($this);
111 95
         $field->setLocale($this->locale);
112  
-        $field->setGenerator($this->generator);
113  
-
114  
-        if ($this->translator !== null) {
115  
-            $field->setTranslator($this->translator);
116  
-        }
117 96
 
118 97
         $data = $this->getTransformedData();
119 98
 
... ...
@@ -367,7 +346,7 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
367 346
     /**
368 347
      * {@inheritDoc}
369 348
      */
370  
-    public function addError($message, PropertyPath $path = null, $type = null)
  349
+    public function addError($messageTemplate, array $messageParameters = array(), PropertyPath $path = null, $type = null)
371 350
     {
372 351
         if ($path !== null) {
373 352
             if ($type === self::FIELD_ERROR && $path->hasNext()) {
... ...
@@ -378,7 +357,7 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
378 357
                 }
379 358
 
380 359
                 if ($this->has($path->getCurrent()) && !$this->get($path->getCurrent())->isHidden()) {
381  
-                    $this->get($path->getCurrent())->addError($message, $path, $type);
  360
+                    $this->get($path->getCurrent())->addError($messageTemplate, $messageParameters, $path, $type);
382 361
 
383 362
                     return;
384 363
                 }
... ...
@@ -395,7 +374,7 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
395 374
                                 $path->next();
396 375
                             }
397 376
 
398  
-                            $field->addError($message, $path, $type);
  377
+                            $field->addError($messageTemplate, $messageParameters, $path, $type);
399 378
 
400 379
                             return;
401 380
                         }
... ...
@@ -404,7 +383,7 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
404 383
             }
405 384
         }
406 385
 
407  
-        parent::addError($message);
  386
+        parent::addError($messageTemplate, $messageParameters);
408 387
     }
409 388
 
410 389
     /**
... ...
@@ -424,67 +403,6 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
424 403
     }
425 404
 
426 405
     /**
427  
-     * Sets the renderer.
428  
-     *
429  
-     * @param RendererInterface $renderer
430  
-     */
431  
-    public function setRenderer(RendererInterface $renderer)
432  
-    {
433  
-        $this->renderer = $renderer;
434  
-    }
435  
-
436  
-    /**
437  
-     * Returns the current renderer.
438  
-     *
439  
-     * @return RendererInterface
440  
-     */
441  
-    public function getRenderer()
442  
-    {
443  
-        return $this->renderer;
444  
-    }
445  
-
446  
-    /**
447  
-     * Delegates the rendering of the field to the renderer set.
448  
-     *
449  
-     * @return string The rendered widget
450  
-     */
451  
-    public function render(array $attributes = array())
452  
-    {
453  
-        $this->injectLocaleAndTranslator($this->renderer);
454  
-
455  
-        return $this->renderer->render($this, $attributes);
456  
-    }
457  
-
458  
-    /**
459  
-     * Delegates the rendering of the field to the renderer set.
460  
-     *
461  
-     * @return string The rendered widget
462  
-     */
463  
-    public function renderErrors()
464  
-    {
465  
-        $this->injectLocaleAndTranslator($this->renderer);
466  
-
467  
-        return $this->renderer->renderErrors($this);
468  
-    }
469  
-    /**
470  
-     * Renders hidden form fields.
471  
-     *
472  
-     * @param boolean $recursive False will prevent hidden fields from embedded forms from rendering
473  
-     *
474  
-     * @return string
475  
-     */
476  
-    public function renderHiddenFields($recursive = true)
477  
-    {
478  
-        $output = '';
479  
-
480  
-        foreach ($this->getHiddenFields($recursive) as $field) {
481  
-            $output .= $field->render();
482  
-        }
483  
-
484  
-        return $output;
485  
-    }
486  
-
487  
-    /**
488 406
      * Returns true if the bound field exists (implements the \ArrayAccess interface).
489 407
      *
490 408
      * @param string $key The key of the bound field
... ...
@@ -566,33 +484,4 @@ class FieldGroup extends Field implements \IteratorAggregate, FieldGroupInterfac
566 484
             $field->setLocale($locale);
567 485
         }
568 486
     }
569  
-
570  
-    /**
571  
-     * Sets the translator of this field.
572  
-     *
573  
-     * @see Translatable
574  
-     */
575  
-    public function setTranslator(TranslatorInterface $translator)
576  
-    {
577  
-        parent::setTranslator($translator);
578  
-
579  
-        foreach ($this->fields as $field) {
580  
-            $field->setTranslator($translator);
581  
-        }
582  
-    }
583  
-
584  
-    /**
585  
-     * Distributes the generator among all nested fields
586  
-     *
587  
-     * @param HtmlGeneratorInterface $generator
588  
-     */
589  
-    public function setGenerator(HtmlGeneratorInterface $generator)
590  
-    {
591  
-        parent::setGenerator($generator);
592  
-
593  
-        // TESTME
594  
-        foreach ($this->fields as $field) {
595  
-            $field->setGenerator($generator);
596  
-        }
597  
-    }
598 487
 }
Txt src/Symfony/Component/Form/FieldInterface.php
  • View file @ 4027f75
... ...
@@ -18,7 +18,7 @@ use Symfony\Component\I18N\TranslatorInterface;
18 18
  *
19 19
  * @author     Bernhard Schussek <bernhard.schussek@symfony-project.com>
20 20
  */
21  
-interface FieldInterface extends Localizable, Translatable
  21
+interface FieldInterface extends Localizable
22 22
 {
23 23
     /**
24 24
      * Marks a constraint violation in a form field
... ...
@@ -185,23 +185,7 @@ interface FieldInterface extends Localizable, Translatable
185 185
      * @param PropertyPath $path
186 186
      * @param ConstraintViolation$violation
187 187
      */
188  
-    public function addError($message, PropertyPath $path = null, $type = null);
189  
-
190  
-    /**
191  
-     * Renders this field.
192  
-     *
193  
-     * @param  array $attributes  The attributes to include in the rendered
194  
-     *                            output
195  
-     * @return string             The rendered output of this field
196  
-     */
197  
-    public function render(array $attributes = array());
198  
-
199  
-    /**
200  
-     * Renders the errors of this field.
201  
-     *
202  
-     * @return string  The rendered output of the field errors
203  
-     */
204  
-    public function renderErrors();
  188
+    function addError($messageTemplate, array $messageParameters = array(), PropertyPath $path = null, $type = null);
205 189
 
206 190
     /**
207 191
      * Returns whether the field is bound.
... ...
@@ -261,14 +245,4 @@ interface FieldInterface extends Localizable, Translatable
261 245
      * @param boolean $required
262 246
      */
263 247
     public function setRequired($required);
264  
-
265  
-    /**
266  
-     * Sets the generator used for rendering HTML.
267  
-     *
268  
-     * Usually there is one generator instance shared between all fields of a
269  
-     * form.
270  
-     *
271  
-     * @param string $charset
272  
-     */
273  
-    public function setGenerator(HtmlGeneratorInterface $generator);
274 248
 }
Txt src/Symfony/Component/Form/FileField.php
  • View file @ 4027f75
... ...
@@ -19,11 +19,11 @@ class FileField extends InputField
19 19
     /**
20 20
      * {@inheritDoc}
21 21
      */
22  
-    public function render(array $attributes = array())
  22
+    public function getAttributes()
23 23
     {
24  
-        return parent::render(array_merge(array(
  24
+        return array_merge(parent::getAttributes(), array(
25 25
             'type' => 'file',
26  
-        ), $attributes));
  26
+        ));
27 27
     }
28 28
 
29 29
     /**
Txt src/Symfony/Component/Form/Form.php
  • View file @ 4027f75
... ...
@@ -12,7 +12,6 @@ namespace Symfony\Component\Form;
12 12
  */
13 13
 
14 14
 use Symfony\Component\Validator\ValidatorInterface;
15  
-use Symfony\Component\I18N\TranslatorInterface;
16 15
 
17 16
 /**
18 17
  * Form represents a form.
... ...
@@ -34,7 +33,6 @@ class Form extends FieldGroup
34 33
     protected static $defaultCsrfProtection = false;
35 34
     protected static $defaultCsrfFieldName = '_token';
36 35
     protected static $defaultLocale = null;
37  
-    protected static $defaultTranslator = null;
38 36
 
39 37
     protected $validator = null;
40 38
     protected $validationGroups = null;
... ...
@@ -51,7 +49,6 @@ class Form extends FieldGroup
51 49
      */
52 50
     public function __construct($name, $object, ValidatorInterface $validator, array $options = array())
53 51
     {
54  
-        $this->generator = new HtmlGenerator();
55 52
         $this->validator = $validator;
56 53
 
57 54
         $this->setData($object);
... ...
@@ -71,27 +68,10 @@ class Form extends FieldGroup
71 68
             $this->setLocale(self::$defaultLocale);
72 69
         }
73 70
 
74  
-        if (self::$defaultTranslator !== null) {
75  
-            $this->setTranslator(self::$defaultTranslator);
76  
-        }
77  
-
78 71
         parent::__construct($name, $options);
79 72
     }
80 73
 
81 74
     /**
82  
-     * Sets the charset used for rendering HTML
83  
-     *
84  
-     * This method overrides the internal HTML generator! If you want to use
85  
-     * your own generator, use setGenerator() instead.
86  
-     *
87  
-     * @param string $charset
88  
-     */
89  
-    public function setCharset($charset)
90  
-    {
91  
-        $this->setGenerator(new HtmlGenerator($charset));
92  
-    }
93  
-
94  
-    /**
95 75
      * Sets the validation groups for this form.
96 76
      *
97 77
      * @param array|string $validationGroups
... ...
@@ -132,26 +112,6 @@ class Form extends FieldGroup
132 112
     }
133 113
 
134 114
     /**
135  
-     * Sets the default translator for newly created forms.
136  
-     *
137  
-     * @param TranslatorInterface $defaultTranslator
138  
-     */
139  
-    static public function setDefaultTranslator(TranslatorInterface $defaultTranslator)
140  
-    {
141  
-        self::$defaultTranslator = $defaultTranslator;
142  
-    }
143  
-
144  
-    /**
145  
-     * Returns the default translator for newly created forms.
146  
-     *
147  
-     * @return TranslatorInterface
148  
-     */
149  
-    static public function getDefaultTranslator()
150  
-    {
151  
-        return self::$defaultTranslator;
152  
-    }
153  
-
154  
-    /**
155 115
      * Binds the form with values and files.
156 116
      *
157 117
      * This method is final because it is very easy to break a form when
... ...
@@ -191,7 +151,7 @@ class Form extends FieldGroup
191 151
                         $type = self::FIELD_ERROR;
192 152
                     }
193 153
 
194  
-                    $this->addError($violation->getMessage(), $propertyPath, $type);
  154
+                    $this->addError($violation->getMessageTemplate(), $violation->getMessageParameters(), $propertyPath, $type);
195 155
                 }
196 156
             }
197 157
         }
... ...
@@ -209,26 +169,6 @@ class Form extends FieldGroup
209 169
     }
210 170
 
211 171
     /**
212  
-     * Gets the stylesheet paths associated with the form.
213  
-     *
214  
-     * @return array An array of stylesheet paths
215  
-     */
216  
-    public function getStylesheets()
217  
-    {
218  
-        return $this->getWidget()->getStylesheets();
219  
-    }
220  
-
221  
-    /**
222  
-     * Gets the JavaScript paths associated with the form.
223  
-     *
224  
-     * @return array An array of JavaScript paths
225  
-     */
226  
-    public function getJavaScripts()
227  
-    {
228  
-        return $this->getWidget()->getJavaScripts();
229  
-    }
230  
-
231  
-    /**
232 172
      * Returns a CSRF token for the set CSRF secret
233 173
      *
234 174
      * If you want to change the algorithm used to compute the token, you
... ...
@@ -386,28 +326,6 @@ class Form extends FieldGroup
386 326
     }
387 327
 
388 328
     /**
389  
-     * Renders the form tag.
390  
-     *
391  
-     * This method only renders the opening form tag.
392  
-     * You need to close it after the form rendering.
393  
-     *
394  
-     * This method takes into account the multipart widgets.
395  
-     *
396  
-     * @param  string $url         The URL for the action
397  
-     * @param  array  $attributes  An array of HTML attributes
398  
-     *
399  
-     * @return string An HTML representation of the opening form tag
400  
-     */
401  
-    public function renderFormTag($url, array $attributes = array())
402  
-    {
403  
-        return sprintf('<form%s>', $this->generator->attributes(array_merge(array(
404  
-            'action' => $url,
405  
-            'method' => isset($attributes['method']) ? strtolower($attributes['method']) : 'post',
406  
-            'enctype' => $this->isMultipart() ? 'multipart/form-data' : null,
407  
-        ), $attributes)));
408  
-    }
409  
-
410  
-    /**
411 329
      * Returns whether the maximum POST size was reached in this request.
412 330
      *
413 331
      * @return boolean
Txt src/Symfony/Component/Form/HiddenField.php
  • View file @ 4027f75
... ...
@@ -21,11 +21,11 @@ class HiddenField extends InputField
21 21
     /**
22 22
      * {@inheritDoc}
23 23
      */
24  
-    public function render(array $attributes = array())
  24
+    public function getAttributes()
25 25
     {
26  
-        return parent::render(array_merge(array(
27  
-            'type'    => 'hidden',
28  
-        ), $attributes));
  26
+        return array_merge(parent::getAttributes(), array(
  27
+            'type' => 'hidden',
  28
+        ));
29 29
     }
30 30
 
31 31
     /**
Txt src/Symfony/Component/Form/HybridField.php
  • View file @ 4027f75
... ...
@@ -48,6 +48,21 @@ class HybridField extends FieldGroup
48 48
         $this->mode = $mode;
49 49
     }
50 50
 
  51
+    public function isField()
  52
+    {
  53
+        return self::FIELD === $this->mode;
  54
+    }
  55
+
  56
+    public function isGroup()
  57
+    {
  58
+        return self::GROUP === $this->mode;
  59
+    }
  60
+
  61
+    public function getFieldMode()
  62
+    {
  63
+        return $this->mode;
  64
+    }
  65
+
51 66
     /**
52 67
      * {@inheritDoc}
53 68
      *
Txt src/Symfony/Component/Form/InputField.php
  • View file @ 4027f75
... ...
@@ -21,13 +21,13 @@ abstract class InputField extends Field
21 21
     /**
22 22
      * {@inheritDoc}
23 23
      */
24  
-    public function render(array $attributes = array())
  24
+    public function getAttributes()
25 25
     {
26  
-        return $this->generator->tag('input', array_merge(array(
27  
-            'id'          => $this->getId(),
28  
-            'name'        => $this->getName(),
29  
-            'value'       => $this->getDisplayedData(),
30  
-            'disabled'    => $this->isDisabled(),
31  
-        ), $attributes));
  26
+        return array_merge(parent::getAttributes(), array(
  27
+            'id'       => $this->getId(),
  28
+            'name'     => $this->getName(),
  29
+            'value'    => $this->getDisplayedData(),
  30
+            'disabled' => $this->isDisabled(),
  31
+        ));
32 32
     }
33 33
 }
Txt src/Symfony/Component/Form/MoneyField.php
  • View file @ 4027f75
... ...
@@ -48,36 +48,24 @@ class MoneyField extends NumberField
48 48
     }
49 49
 
50 50
     /**
51  
-     * {@inheritDoc}
52  
-     */
53  
-    public function render(array $attributes = array())
54  
-    {
55  
-        $input = parent::render($attributes);
56  
-
57  
-        if ($this->getOption('currency')) {
58  
-            return str_replace('%widget%', $input, $this->getPattern($this->locale, $this->getOption('currency')));
59  
-        } else {
60  
-            return $input;
61  
-        }
62  
-    }
63  
-
64  
-    /**
65 51
      * Returns the pattern for this locale
66 52
      *
67  
-     * The pattern contains the placeholder "%widget%" where the HTML tag should
  53
+     * The pattern contains the placeholder "{{ widget }}" where the HTML tag should
68 54
      * be inserted
69  
-     *
70  
-     * @param string $locale
71 55
      */
72  
-    protected static function getPattern($locale, $currency)
  56
+    protected function getPattern()
73 57
     {
74  
-        if (!isset(self::$patterns[$locale])) {
75  
-            self::$patterns[$locale] = array();
  58
+        if (!$this->getOption('currency')) {
  59
+            return '{{ widget }}';
  60
+        }
  61
+
  62
+        if (!isset(self::$patterns[$this->locale])) {
  63
+            self::$patterns[$this->locale] = array();
76 64
         }
77 65
 
78  
-        if (!isset(self::$patterns[$locale][$currency])) {
79  
-            $format = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
80  
-            $pattern = $format->formatCurrency('123', $currency);
  66
+        if (!isset(self::$patterns[$this->locale][$this->getOption('currency')])) {
  67
+            $format = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
  68
+            $pattern = $format->formatCurrency('123', $this->getOption('currency'));
81 69
 
82 70
             // the spacings between currency symbol and number are ignored, because
83 71
             // a single space leads to better readability in combination with input
... ...
@@ -88,14 +76,14 @@ class MoneyField extends NumberField
88 76
             preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches);
89 77
 
90 78
             if (!empty($matches[1])) {
91  
-                self::$patterns[$locale] = $matches[1].' %widget%';
  79
+                self::$patterns[$this->locale] = $matches[1].' {{ widget }}';
92 80
             } else if (!empty($matches[2])) {
93  
-                self::$patterns[$locale] = '%widget% '.$matches[2];
  81
+                self::$patterns[$this->locale] = '{{ widget }} '.$matches[2];
94 82
             } else {
95  
-                self::$patterns[$locale] = '%widget%';
  83
+                self::$patterns[$this->locale] = '{{ widget }}';
96 84
             }
97 85
         }
98 86
 
99  
-        return self::$patterns[$locale];
  87
+        return self::$patterns[$this->locale];
100 88
     }
101  
-}
102 89
\ No newline at end of file
  90
+}
Txt src/Symfony/Component/Form/NumberField.php
  • View file @ 4027f75
... ...
@@ -40,10 +40,10 @@ class NumberField extends InputField
40 40
     /**
41 41
      * {@inheritDoc}
42 42
      */
43  
-    public function render(array $attributes = array())
  43
+    public function getAttributes(array $attributes = array())
44 44
     {
45  
-        return parent::render(array_merge(array(
  45
+        return array_merge(parent::getAttributes(), array(
46 46
             'type'  => 'text',
47  
-        ), $attributes));
  47
+        ));
48 48
     }
49 49
 }
Txt src/Symfony/Component/Form/PasswordField.php
  • View file @ 4027f75
... ...
@@ -31,11 +31,11 @@ class PasswordField extends TextField
31 31
     /**
32 32
      * {@inheritDoc}
33 33
      */
34  
-    public function render(array $attributes = array())
  34
+    public function getAttributes()
35 35
     {
36  
-        return parent::render(array_merge(array(
  36
+        return array_merge(parent::getAttributes(), array(
37 37
             'value'       => $this->getOption('always_empty') && !$this->isBound() ? '' : $this->getDisplayedData(),
38 38
             'type'        => 'password',
39  
-        ), $attributes));
  39
+        ));
40 40
     }
41 41
 }
42 42
\ No newline at end of file
Txt src/Symfony/Component/Form/PercentField.php
  • View file @ 4027f75
... ...
@@ -36,12 +36,4 @@ class PercentField extends NumberField
36 36
             'type' => $this->getOption('type'),
37 37
         )));
38 38
     }
39  
-
40  
-    /**
41  
-     * {@inheritDoc}
42  
-     */
43  
-    public function render(array $attributes = array())
44  
-    {
45  
-        return parent::render($attributes).' %';
46  
-    }
47 39
 }
Txt src/Symfony/Component/Form/RadioField.php
  • View file @ 4027f75
... ...
@@ -21,11 +21,11 @@ class RadioField extends ToggleField
21 21
     /**
22 22
      * {@inheritDoc}
23 23
      */
24  
-    public function render(array $attributes = array())
  24
+    public function getAttributes()
25 25
     {
26  
-        return parent::render(array_merge(array(
  26
+        return array_merge(parent::getAttributes(), array(
27 27
             'type' => 'radio',
28 28
             'name' => $this->getParent() ? $this->getParent()->getName() : $this->getName(),
29  
-        ), $attributes));
  29
+        ));
30 30
     }
31 31
 }
Txt src/Symfony/Component/Form/Renderer/Renderer.php
  • View file @ 4027f75
... ...
@@ -1,88 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Component\Form\Renderer;
4  
-
5  
-use Symfony\Component\I18N\TranslatorInterface;
6  
-use Symfony\Component\Form\FieldInterface;
7  
-use Symfony\Component\Form\HtmlGeneratorInterface;
8  
-use Symfony\Component\Form\Configurable;
9  
-
10  
-/**
11  
- * BaseRenderer is the base class for all renderers.
12  
- */
13  
-abstract class Renderer extends Configurable implements RendererInterface
14  
-{
15  
-    /**
16  
-     * The generator used for rendering the HTML
17  
-     * @var HtmlGeneratorInterface
18  
-     */
19  
-    protected $generator;
20  
-
21  
-    /**
22  
-     * Gets the stylesheet paths associated with the renderer.
23  
-     *
24  
-     * The array keys are files and values are the media names (separated by a ,):
25  
-     *
26  
-     *   array('/path/to/file.css' => 'all', '/another/file.css' => 'screen,print')
27  
-     *
28  
-     * @return array An array of stylesheet paths
29  
-     */
30  
-    public function getStylesheets()
31  
-    {
32  
-        return array();
33  
-    }
34  
-
35  
-    /**
36  
-     * Gets the JavaScript paths associated with the renderer.
37  
-     *
38  
-     * @return array An array of JavaScript paths
39  
-     */
40  
-    public function getJavaScripts()
41  
-    {
42  
-        return array();
43  
-    }
44  
-
45  
-    /**
46  
-     * {@inheritDoc}
47  
-     */
48  
-    public function renderErrors(FieldInterface $field)
49  
-    {
50  
-        $html = '';
51  
-
52  
-        if ($field->hasErrors()) {
53  
-            $html .= "<ul>\n";
54  
-
55  
-            foreach ($field->getErrors() as $error) {
56  
-                $html .= "<li>" . $error . "</li>\n";
57  
-            }
58  
-
59  
-            $html .= "</ul>\n";
60  
-        }
61  
-
62  
-        return $html;
63  
-    }
64  
-
65  
-    /**
66  
-     * {@inheritDoc}
67  
-     */
68  
-    public function setTranslator(TranslatorInterface $translator)
69  
-    {
70  
-        // TODO
71  
-    }
72  
-
73  
-    /**
74  
-     * {@inheritDoc}
75  
-     */
76  
-    public function setLocale($locale)
77  
-    {
78  
-        // TODO
79  
-    }
80  
-
81  
-    /**
82  
-     * {@inheritDoc}
83  
-     */
84  
-    public function setGenerator(HtmlGeneratorInterface $generator)
85  
-    {
86  
-        $this->generator = $generator;
87  
-    }
88  
-}
Txt src/Symfony/Component/Form/Renderer/RendererInterface.php
  • View file @ 4027f75
... ...
@@ -1,45 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Component\Form\Renderer;
4  
-
5  
-use Symfony\Component\Form\HtmlGeneratorInterface;
6  
-use Symfony\Component\Form\FieldInterface;
7  
-use Symfony\Component\Form\Localizable;
8  
-use Symfony\Component\Form\Translatable;
9  
-
10  
-/**
11  
- * Renders a given form field.
12  
- *
13  
- * @author     Bernhard Schussek <bernhard.schussek@symfony-project.com>
14  
- */
15  
-interface RendererInterface extends Localizable, Translatable
16  
-{
17  
-    /**
18  
-     * Sets the generator used for rendering the HTML
19  
-     *
20  
-     * @param HtmlGeneratorInterface $generator
21  
-     */
22  
-    public function setGenerator(HtmlGeneratorInterface $generator);
23  
-
24  
-    /**
25  
-     * Returns the textual representation of the given field.
26  
-     *
27  
-     * @param  FieldInterface $field      The form field
28  
-     * @param  array $attributes          The attributes to include in the
29  
-     *                                    rendered output
30  
-     * @return string                     The rendered output
31  
-     * @throws InvalidArgumentException   If the $field is not instance of the
32  
-     *                                    expected class
33  
-     */
34  
-    public function render(FieldInterface $field, array $attributes = array());
35  
-
36  
-    /**
37  
-     * Returns the textual representation of the errors of the given field.
38  
-     *
39  
-     * @param  FieldInterface $field      The form field
40  
-     * @return string                     The rendered output
41  
-     * @throws InvalidArgumentException   If the $field is not instance of the
42  
-     *                                    expected class
43  
-     */
44  
-    public function renderErrors(FieldInterface $field);
45  
-}
46 0
\ No newline at end of file
Txt src/Symfony/Component/Form/Renderer/TableRenderer.php
  • View file @ 4027f75
... ...
@@ -1,52 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Component\Form\Renderer;
4  
-
5  
-use Symfony\Component\Form\FieldInterface;
6  
-
7  
-/*
8  
- * This file is part of the symfony package.
9  
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
10  
- *
11  
- * For the full copyright and license information, please view the LICENSE
12  
- * file that was distributed with this source code.
13  
- */
14  
-
15  
-/**
16  
- * Renders a field group as HTML table
17  
- *
18  
- * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
19  
- */
20  
-class TableRenderer extends Renderer
21  
-{
22  
-    /**
23  
-     * {@inheritDoc}
24  
-     */
25  
-    public function render(FieldInterface $group, array $attributes = array())
26  
-    {
27  
-        $html = "<table>\n";
28  
-
29  
-        foreach ($group as $field) {
30  
-            $label = self::humanize($field->getKey());
31  
-
32  
-            $html .= "<tr>\n";
33  
-            $html .= "<td><label for=\"{$field->getId()}\">$label</label></td>\n";
34  
-            $html .= "<td>\n";
35  
-            if ($field->hasErrors()) {
36  
-                $html .= $field->renderErrors()."\n";
37  
-            }
38  
-            $html .= $field->render()."\n";
39  
-            $html .= "</td>";
40  
-            $html .= "</tr>\n";
41  
-        }
42  
-
43  
-        $html .= "</table>\n";
44  
-
45  
-        return $html;
46  
-    }
47  
-
48  
-    protected static function humanize($text)
49  
-    {
50  
-        return ucfirst(strtolower(str_replace('_', ' ', $text)));
51  
-    }
52  
-}
Txt src/Symfony/Component/Form/TextField.php
  • View file @ 4027f75
... ...
@@ -31,11 +31,11 @@ class TextField extends InputField
31 31
     /**
32 32
      * {@inheritDoc}
33 33
      */
34  
-    public function render(array $attributes = array())
  34
+    public function getAttributes()
35 35
     {
36  
-        return parent::render(array_merge(array(
  36
+        return array_merge(parent::getAttributes(), array(
37 37
             'type'        => 'text',
38 38
             'maxlength'   => $this->getOption('max_length'),
39  
-        ), $attributes));
  39
+        ));
40 40
     }
41 41
 }
Txt src/Symfony/Component/Form/TextareaField.php
  • View file @ 4027f75
... ...
@@ -21,15 +21,13 @@ class TextareaField extends Field
21 21
     /**
22 22
      * {@inheritDoc}
23 23
      */
24  
-    public function render(array $attributes = array())
  24
+    public function getAttributes()
25 25
     {
26  
-        $content = $this->generator->escape($this->getDisplayedData());
27  
-
28  
-        return $this->generator->contentTag('textarea', $content, array_merge(array(
  26
+        return array_merge(parent::getAttributes(), array(
29 27
             'id'    => $this->getId(),
30 28
             'name'  => $this->getName(),
31 29
             'rows'  => 4,
32 30
             'cols'  => 30,
33  
-        ), $attributes));
  31
+        ));
34 32
     }
35 33
 }
Txt src/Symfony/Component/Form/TimeField.php
  • View file @ 4027f75
... ...
@@ -107,25 +107,23 @@ class TimeField extends FieldGroup
107 107
         $this->setValueTransformer(new ValueTransformerChain($transformers));
108 108
     }
109 109
 
  110
+    public function isField()
  111
+    {
  112
+        return self::INPUT === $this->getOption('widget');
  113
+    }
  114
+
110 115
     /**
111 116
      * {@inheritDoc}
112 117
      */
113  
-    public function render(array $attributes = array())
  118
+    public function getAttributes()
114 119
     {
115  
-        if ($this->getOption('widget') == self::INPUT) {
116  
-            $attributes = array_merge(array(
  120
+        if ($this->isField()) {
  121
+            return array_merge(parent::getAttributes(), array(
117 122
                 'size' => '1',
118  
-            ), $attributes);
119  
-        }
120  
-
121  
-        $html = $this->get('hour')->render($attributes);
122  
-        $html .= ':' . $this->get('minute')->render($attributes);
123  
-
124  
-        if ($this->getOption('with_seconds')) {
125  
-            $html .= ':' . $this->get('second')->render($attributes);
  123
+            ));
126 124
         }
127 125
 
128  
-        return $html;
  126
+        return parent::getAttributes();
129 127
     }
130 128
 
131 129
     /**
Txt src/Symfony/Component/Form/ToggleField.php
  • View file @ 4027f75
... ...
@@ -27,7 +27,6 @@ abstract class ToggleField extends InputField
27 27
     {
28 28
         $this->addOption('value');
29 29
         $this->addOption('label');
30  
-        $this->addOption('translate_label', false);
31 30
 
32 31
         $this->setValueTransformer(new BooleanToStringTransformer());
33 32
     }
... ...
@@ -35,23 +34,11 @@ abstract class ToggleField extends InputField
35 34
     /**
36 35
      * {@inheritDoc}
37 36
      */
38  
-    public function render(array $attributes = array())
  37
+    public function getAttributes()
39 38
     {
40  
-        $html = parent::render(array_merge(array(
41  
-            'value'     => $this->getOption('value'),
42  
-            'checked'    => ((string)$this->getDisplayedData() !== '' && $this->getDisplayedData() !== 0),
43  
-        ), $attributes));
44  
-
45  
-        if ($label = $this->getOption('label')) {
46  
-            if ($this->getOption('translate_label')) {
47  
-                $label = $this->translate($label);
48  
-            }
49  
-
50  
-            $html .= ' '.$this->generator->contentTag('label', $label, array(
51  
-                'for' => $this->getId(),
52  
-            ));
53  
-        }
54  
-
55  
-        return $html;
  39
+        return array_merge(parent::getAttributes(), array(
  40
+            'value'   => $this->getOption('value'),
  41
+            'checked' => (string) $this->getDisplayedData() !== '' && $this->getDisplayedData() !== 0,
  42
+        ));
56 43
     }
57 44
 }
Txt src/Symfony/Component/Form/Translatable.php
  • View file @ 4027f75
... ...
@@ -1,20 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Component\Form;
4  
-
5  
-use Symfony\Component\I18N\TranslatorInterface;
6  
-
7  
-/**
8  
- * Marks classes that you can inject a translator into.
9  
- *
10  
- * @author     Bernhard Schussek <bernhard.schussek@symfony-project.com>
11  
- */
12  
-interface Translatable
13  
-{
14  
-    /**
15  
-     * Sets the translator unit of the class.
16  
-     *
17  
-     * @param TranslatorInterface $translator
18  
-     */
19  
-    public function setTranslator(TranslatorInterface $translator);
20  
-}
Txt src/Symfony/Component/I18N/TranslatorInterface.php
  • View file @ 4027f75
... ...
@@ -1,22 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Component\I18N;
4  
-
5  
-/**
6  
- * A translator used for translating text.
7  
- *
8  
- * @author     Bernhard Schussek <bernhard.schussek@symfony-project.com>
9  
- */
10  
-interface TranslatorInterface
11  
-{
12  
-    /**
13  
-     * Translates a given text string.
14  
-     *
15  
-     * @param string $text        The text to translate
16  
-     * @param array  $parameters  The parameters to inject into the text
17  
-     * @param string $locale      The locale of the translated text. If null,
18  
-     *                            the preconfigured locale of the translator
19  
-     *                            or the system's default culture is used.
20  
-     */
21  
-    public function translate($text, array $parameters = array(), $locale = null);
22  
-}
23 0
\ No newline at end of file
Txt tests/Symfony/Tests/Component/Form/CheckboxFieldTest.php
  • View file @ 4027f75
... ...
@@ -1,20 +0,0 @@
1  
-<?php
2  
-
3  
-namespace Symfony\Tests\Component\Form;
4  
-
5  
-use Symfony\Component\Form\CheckboxField;
6  
-
7  
-class CheckboxFieldTest extends \PHPUnit_Framework_TestCase
8  
-{
9  
-    public function testRender()
10  
-    {
11  
-        $field = new CheckboxField('name');
12  
-        $field->setData(true);
13  
-
14  
-        $html = '<input id="name" name="name" checked="checked" type="checkbox" class="foobar" />';
15  
-
16  
-        $this->assertEquals($html, $field->render(array(
17  
-            'class' => 'foobar',
18  
-        )));
19  
-    }
20  
-}
21 0
\ No newline at end of file
Txt tests/Symfony/Tests/Component/Form/ChoiceFieldTest.php
  • View file @ 4027f75
... ...
@@ -72,165 +72,6 @@ class ChoiceFieldTest extends \PHPUnit_Framework_TestCase
72 72
         $this->assertEquals('b', $field->getDisplayedData());
73 73
     }
74 74
 
75  
-    public function testRenderSingleNonExpanded()
76  
-    {
77  
-        $field = new ChoiceField('name', array(
78  
-            'multiple' => false,
79  
-            'expanded' => false,
80  
-            'choices' => $this->choices,
81  
-        ));
82  
-
83  
-        $field->setData('b');
84  
-
85  
-        $html = <<<EOF
86  
-<select id="name" name="name" class="foobar">
87  
-<option value="a">Bernhard</option>
88  
-<option value="b" selected="selected">Fabien</option>
89  
-<option value="c">Kris</option>
90  
-<option value="d">Jon</option>
91  
-<option value="e">Roman</option>
92  
-</select>
93  
-EOF;
94  
-
95  
-        $this->assertEquals($html, $field->render(array(
96  
-            'class' => 'foobar',
97  
-        )));
98  
-    }
99  
-
100  
-    public function testRenderSingleNonExpanded_translateChoices()
101  
-    {
102  
-        $translator = $this->getMock('Symfony\Component\I18N\TranslatorInterface');
103  
-        $translator->expects($this->any())
104  
-                             ->method('translate')
105  
-                             ->will($this->returnCallback(function($text) {
106  
-                                 return 'translated['.$text.']';
107  
-                             }));
108  
-
109  
-        $field = new ChoiceField('name', array(
110  
-            'multiple' => false,
111  
-            'expanded' => false,
112  
-            'choices' => $this->choices,
113  
-            'translate_choices' => true,
114  
-        ));
115  
-
116  
-        $field->setTranslator($translator);
117  
-        $field->setData('b');
118  
-
119  
-        $html = <<<EOF
120  
-<select id="name" name="name" class="foobar">
121  
-<option value="a">translated[Bernhard]</option>
122  
-<option value="b" selected="selected">translated[Fabien]</option>
123  
-<option value="c">translated[Kris]</option>
124  
-<option value="d">translated[Jon]</option>
125  
-<option value="e">translated[Roman]</option>
126  
-</select>
127  
-EOF;
128  
-
129  
-        $this->assertEquals($html, $field->render(array(
130  
-            'class' => 'foobar',
131  
-        )));
132  
-    }
133  
-
134  
-    public function testRenderSingleNonExpanded_disabled()
135  
-    {
136  
-        $field = new ChoiceField('name', array(
137  
-            'multiple' => false,
138  
-            'expanded' => false,
139  
-            'choices' => $this->choices,
140  
-            'disabled' => true,
141  
-        ));
142  
-
143  
-
144  
-        $html = <<<EOF
145  
-<select id="name" name="name" disabled="disabled">
146  
-<option value="a">Bernhard</option>
147  
-<option value="b">Fabien</option>
148  
-<option value="c">Kris</option>
149  
-<option value="d">Jon</option>
150  
-<option value="e">Roman</option>
151  
-</select>
152  
-EOF;
153  
-
154  
-        $this->assertEquals($html, $field->render());
155  
-    }
156  
-
157  
-    public function testRenderSingleNonExpandedWithPreferred()
158  
-    {
159  
-        $field = new ChoiceField('name', array(
160  
-            'multiple' => false,
161  
-            'expanded' => false,
162  
-            'choices' => $this->choices,
163  
-            'preferred_choices' => $this->preferredChoices,
164  
-            'separator' => '---',
165  
-        ));
166  
-
167  
-        $field->setData('d');
168  
-
169  
-        $html = <<<EOF
170  
-<select id="name" name="name">
171  
-<option value="d" selected="selected">Jon</option>
172  
-<option value="e">Roman</option>
173  
-<option disabled="disabled">---</option>
174  
-<option value="a">Bernhard</option>
175  
-<option value="b">Fabien</option>
176  
-<option value="c">Kris</option>
177  
-</select>
178  
-EOF;
179  
-
180  
-        $this->assertEquals($html, $field->render());
181  
-    }
182  
-
183  
-    public function testRenderSingleNonExpandedWithGroups()
184  
-    {
185  
-        $field = new ChoiceField('name', array(
186  
-            'multiple' => false,
187  
-            'expanded' => false,
188  
-            'choices' => $this->groupedChoices,
189  
-        ));
190  
-
191  
-        $html = <<<EOF
192  
-<select id="name" name="name">
193  
-<optgroup label="Symfony">
194  
-<option value="a">Bernhard</option>
195  
-<option value="b">Fabien</option>
196  
-<option value="c">Kris</option>
197  
-</optgroup>
198  
-<optgroup label="Doctrine">
199  
-<option value="d">Jon</option>
200  
-<option value="e">Roman</option>
201  
-</optgroup>
202  
-</select>
203  
-EOF;
204  
-
205  
-        $this->assertEquals($html, $field->render());
206  
-    }
207  
-
208  
-    public function testRenderSingleNonExpandedNonRequired()
209  
-    {
210  
-        $field = new ChoiceField('name', array(
211  
-            'multiple' => false,
212  
-            'expanded' => false,
213  
-            'choices' => $this->choices,
214  
-            'empty_value' => 'empty',
215  
-        ));
216  
-
217  
-        $field->setData(null);
218  
-        $field->setRequired(false);
219  
-
220  
-        $html = <<<EOF
221  
-<select id="name" name="name">
222  
-<option value="" selected="selected">empty</option>
223  
-<option value="a">Bernhard</option>
224  
-<option value="b">Fabien</option>
225  
-<option value="c">Kris</option>
226  
-<option value="d">Jon</option>
227  
-<option value="e">Roman</option>
228  
-</select>
229  
-EOF;
230  
-
231  
-        $this->assertEquals($html, $field->render());
232  
-    }
233  
-
234 75
     public function testBindMultipleNonExpanded()
235 76
     {
236 77
         $field = new ChoiceField('name', array(
... ...
@@ -245,29 +86,6 @@ EOF;
245 86
         $this->assertEquals(array('a', 'b'), $field->getDisplayedData());
246 87
     }
247 88
 
248  
-    public function testRenderMultipleNonExpanded()
249  
-    {
250  
-        $field = new ChoiceField('name', array(
251  
-            'multiple' => true,
252  
-            'expanded' => false,
253  
-            'choices' => $this->choices,
254  
-        ));
255  
-
256  
-        $field->setData(array('a', 'b'));
257  
-
258  
-        $html = <<<EOF
259  
-<select id="name" name="name[]" multiple="multiple">
260  
-<option value="a" selected="selected">Bernhard</option>
261  
-<option value="b" selected="selected">Fabien</option>
262  
-<option value="c">Kris</option>
263  
-<option value="d">Jon</option>
264  
-<option value="e">Roman</option>
265  
-</select>
266  
-EOF;
267  
-
268  
-        $this->assertEquals($html, $field->render());
269  
-    }
270  
-
271 89
     public function testBindSingleExpanded()
272 90
     {
273 91
         $field = new ChoiceField('name', array(
... ...
@@ -316,80 +134,6 @@ EOF;
316 134
         $this->assertSame(array(0 => '', 1 => '1', 2 => '', 3 => '', 4 => ''), $field->getDisplayedData());
317 135
     }
318 136
 
319  
-    public function testRenderSingleExpanded()
320  
-    {
321  
-        $field = new ChoiceField('name', array(
322  
-            'multiple' => false,
323  
-            'expanded' => true,
324  
-            'choices' => $this->choices,
325  
-        ));
326  
-
327  
-        $field->setData('b');
328  
-
329  
-        $html = <<<EOF
330  
-<input id="name_a" name="name" value="a" type="radio" /> <label for="name_a">Bernhard</label>
331  
-<input id="name_b" name="name" value="b" checked="checked" type="radio" /> <label for="name_b">Fabien</label>
332  
-<input id="name_c" name="name" value="c" type="radio" /> <label for="name_c">Kris</label>
333  
-<input id="name_d" name="name" value="d" type="radio" /> <label for="name_d">Jon</label>
334  
-<input id="name_e" name="name" value="e" type="radio" /> <label for="name_e">Roman</label>
335  
-
336  
-EOF;
337  
-
338  
-        $this->assertEquals($html, $field->render());
339  
-    }
340  
-
341  
-    public function testRenderSingleExpanded_translateChoices()
342  
-    {
343  
-        $translator = $this->getMock('Symfony\Component\I18N\TranslatorInterface');
344  
-        $translator->expects($this->any())
345  
-                             ->method('translate')
346  
-                             ->will($this->returnCallback(function($text) {
347  
-                                 return 'translated['.$text.']';
348  
-                             }));
349  
-
350  
-        $field = new ChoiceField('name', array(
351  
-            'multiple' => false,
352  
-            'expanded' => true,
353  
-            'choices' => $this->choices,
354  
-            'translate_choices' => true,
355  
-        ));
356  
-
357  
-        $field->setTranslator($translator);
358  
-        $field->setData('b');
359  
-
360  
-        $html = <<<EOF
361  
-<input id="name_a" name="name" value="a" type="radio" /> <label for="name_a">translated[Bernhard]</label>
362  
-<input id="name_b" name="name" value="b" checked="checked" type="radio" /> <label for="name_b">translated[Fabien]</label>
363  
-<input id="name_c" name="name" value="c" type="radio" /> <label for="name_c">translated[Kris]</label>
364  
-<input id="name_d" name="name" value="d" type="radio" /> <label for="name_d">translated[Jon]</label>
365  
-<input id="name_e" name="name" value="e" type="radio" /> <label for="name_e">translated[Roman]</label>
366  
-
367  
-EOF;
368  
-
369  
-        $this->assertEquals($html, $field->render());
370  
-    }
371  
-
372  
-    public function testRenderSingleExpandedWithPreferred()
373  
-    {
374  
-        $field = new ChoiceField('name', array(
375  
-            'multiple' => false,
376  
-            'expanded' => true,
377  
-            'choices' => $this->choices,
378  
-            'preferred_choices' => $this->preferredChoices,
379  
-        ));
380  
-
381  
-        $html = <<<EOF
382  
-<input id="name_d" name="name" value="d" type="radio" /> <label for="name_d">Jon</label>
383  
-<input id="name_e" name="name" value="e" type="radio" /> <label for="name_e">Roman</label>
384  
-<input id="name_a" name="name" value="a" type="radio" /> <label for="name_a">Bernhard</label>
385  
-<input id="name_b" name="name" value="b" type="radio" /> <label for="name_b">Fabien</label>
386  
-<input id="name_c" name="name" value="c" type="radio" /> <label for="name_c">Kris</label>
387  
-
388  
-EOF;
389  
-
390  
-        $this->assertEquals($html, $field->render());
391  
-    }
392  
-
393 137
     public function testBindMultipleExpanded()
394 138
     {
395 139
         $field = new ChoiceField('name', array(
... ...
@@ -437,26 +181,4 @@ EOF;
437 181
         $this->assertSame('', $field[4]->getDisplayedData());
438 182
         $this->assertSame(array(0 => '', 1 => '1', 2 => '1', 3 => '', 4 => ''), $field->getDisplayedData());
439 183
     }
440  
-
441  
-    public function testRenderMultipleExpanded()
442  
-    {
443  
-        $field = new ChoiceField('name', array(
444  
-            'multiple' => true,
445  
-            'expanded' => true,
446  
-            'choices' => $this->choices,
447  
-        ));
448  
-
449  
-        $field->setData(array('a', 'b'));
450  
-
451  
-        $html = <<<EOF
452  
-<input id="name_a" name="name[a]" value="a" checked="checked" type="checkbox" /> <label for="name_a">Bernhard</label>
453  
-<input id="name_b" name="name[b]" value="b" checked="checked" type="checkbox" /> <label for="name_b">Fabien</label>
454  
-<input id="name_c" name="name[c]" value="c" type="checkbox" /> <label for="name_c">Kris</label>
455  
-<input id="name_d" name="name[d]" value="d" type="checkbox" /> <label for="name_d">Jon</label>
456  
-<input id="name_e" name="name[e]" value="e" type="checkbox" /> <label for="name_e">Roman</label>
457  
-
458  
-EOF;
459  
-
460  
-        $this->assertEquals($html, $field->render());
461  
-    }
462 184
 }
463 185
\ No newline at end of file
Txt tests/Symfony/Tests/Component/Form/DateFieldTest.php
  • View file @ 4027f75
... ...
@@ -99,119 +99,4 @@ class DateFieldTest extends DateTimeTestCase
99 99
 
100 100
         $this->assertEquals('01.06.2010', $field->getDisplayedData());
101 101
     }
102  
-
103  
-    public function testRenderAsInput()
104  
-    {
105  
-        $field = new DateField('name', array('widget' => 'input'));
106  
-
107  
-        $field->setLocale('de_AT');
108  
-        $field->setData(new \DateTime('2010-06-02 UTC'));
109  
-
110  
-        $html = '<input id="name" name="name" value="02.06.2010" type="text" class="foobar" />';
111  
-
112  
-        $this->assertEquals($html, $field->render(array(
113  
-            'class' => 'foobar',
114  
-        )));
115  
-    }
116  
-
117  
-    public function testRenderAsInputWithFormat()
118  
-    {
119  
-        $field = new DateField('name', array('widget' => 'input', 'format' => 'short'));
120  
-
121  
-        $field->setLocale('de_AT');
122  
-        $field->setData(new \DateTime('2010-06-02 UTC'));
123  
-
124  
-        $html = '<input id="name" name="name" value="02.06.10" type="text" />';
125  
-
126  
-        $this->assertEquals($html, $field->render());
127  
-    }
128  
-
129  
-    public function testRenderAsChoice()
130  
-    {
131  
-        $field = new DateField('name', array(
132  
-            'years' => array(2010, 2011),
133  
-            'months' => array(6, 7),
134  
-            'days' => array(1, 2),
135  
-            'widget' => DateField::CHOICE,
136  
-        ));
137  
-
138  
-        $field->setLocale('de_AT');
139  
-        $field->setData(new \DateTime('2010-06-02 UTC'));
140  
-
141  
-        $html = <<<EOF
142  
-<select id="name_day" name="name[day]" class="foobar">
143  
-<option value="1">01</option>
144  
-<option value="2" selected="selected">02</option>
145  
-</select>.<select id="name_month" name="name[month]" class="foobar">
146  
-<option value="6" selected="selected">06</option>
147  
-<option value="7">07</option>
148  
-</select>.<select id="name_year" name="name[year]" class="foobar">
149  
-<option value="2010" selected="selected">2010</option>
150  
-<option value="2011">2011</option>
151  
-</select>
152  
-EOF;
153  
-
154  
-        $this->assertEquals($html, $field->render(array(
155  
-            'class' => 'foobar',
156  
-        )));
157  
-    }
158  
-
159  
-    public function testRenderAsChoiceNonRequired()
160  
-    {
161  
-        $field = new DateField('name', array(
162  
-            'years' => array(2010, 2011),
163  
-            'months' => array(6, 7),
164  
-            'days' => array(1, 2),
165  
-            'widget' => DateField::CHOICE,
166  
-        ));
167  
-
168  
-        $field->setLocale('de_AT');
169  
-        $field->setRequired(false);
170  
-
171  
-        $html = <<<EOF
172  
-<select id="name_day" name="name[day]">
173  
-<option value="" selected="selected"></option>
174  
-<option value="1">01</option>
175  
-<option value="2">02</option>
176  
-</select>.<select id="name_month" name="name[month]">
177  
-<option value="" selected="selected"></option>
178  
-<option value="6">06</option>
179  
-<option value="7">07</option>
180  
-</select>.<select id="name_year" name="name[year]">
181  
-<option value="" selected="selected"></option>
182  
-<option value="2010">2010</option>
183  
-<option value="2011">2011</option>
184  
-</select>
185  
-EOF;
186  
-
187  
-        $this->assertEquals($html, $field->render());
188  
-    }
189  
-
190  
-    public function testRenderAsChoiceWithPattern()
191  
-    {
192  
-        $field = new DateField('name', array(
193  
-            'years' => array(2010, 2011),
194  
-            'months' => array(6, 7),
195  
-            'days' => array(1, 2),
196  
-            'widget' => DateField::CHOICE,
197  
-            'pattern' => '%day%---%month%---%year%',
198  
-        ));
199  
-
200  
-        $field->setLocale('de_AT');
201  
-
202  
-        $html = <<<EOF
203  
-<select id="name_day" name="name[day]">
204  
-<option value="1">01</option>
205  
-<option value="2">02</option>
206  
-</select>---<select id="name_month" name="name[month]">
207  
-<option value="6">06</option>
208  
-<option value="7">07</option>
209  
-</select>---<select id="name_year" name="name[year]">
210  
-<option value="2010">2010</option>
211  
-<option value="2011">2011</option>
212  
-</select>
213  
-EOF;
214  
-
215  
-        $this->assertEquals($html, $field->render());
216  
-    }
217 102
 }
218 103
\ No newline at end of file
Txt tests/Symfony/Tests/Component/Form/DateTimeFieldTest.php
  • View file @ 4027f75
0 additions, 46 deletions not shown
Txt tests/Symfony/Tests/Component/Form/FieldGroupTest.php
  • View file @ 4027f75
14 additions, 165 deletions not shown
Txt tests/Symfony/Tests/Component/Form/FormTest.php
  • View file @ 4027f75
0 additions, 42 deletions not shown
Txt tests/Symfony/Tests/Component/Form/HiddenFieldTest.php
  • View file @ 4027f75
0 additions, 11 deletions not shown
Txt tests/Symfony/Tests/Component/Form/HtmlGeneratorTest.php
  • View file @ 4027f75
0 additions, 91 deletions not shown
Txt tests/Symfony/Tests/Component/Form/InputFieldTest.php
  • View file @ 4027f75
0 additions, 33 deletions not shown
Txt tests/Symfony/Tests/Component/Form/MoneyFieldTest.php
  • View file @ 4027f75
0 additions, 46 deletions not shown
Txt tests/Symfony/Tests/Component/Form/NumberFieldTest.php
  • View file @ 4027f75
0 additions, 46 deletions not shown
Txt tests/Symfony/Tests/Component/Form/PasswordFieldTest.php
  • View file @ 4027f75
0 additions, 49 deletions not shown
Txt tests/Symfony/Tests/Component/Form/PercentFieldTest.php
  • View file @ 4027f75
0 additions, 46 deletions not shown
Txt tests/Symfony/Tests/Component/Form/RadioFieldTest.php
  • View file @ 4027f75
0 additions, 33 deletions not shown
Txt tests/Symfony/Tests/Component/Form/Renderer/RendererTestCase.php
  • View file @ 4027f75
0 additions, 23 deletions not shown
Txt tests/Symfony/Tests/Component/Form/TextFieldTest.php
  • View file @ 4027f75
0 additions, 28 deletions not shown
Txt tests/Symfony/Tests/Component/Form/TextareaFieldTest.php
  • View file @ 4027f75
0 additions, 28 deletions not shown
Txt tests/Symfony/Tests/Component/Form/TimeFieldTest.php
  • View file @ 4027f75
0 additions, 124 deletions not shown
Txt tests/Symfony/Tests/Component/Form/ToggleFieldTest.php
  • View file @ 4027f75
0 additions, 67 deletions not shown
Txt update_vendors.sh
  • View file @ 4027f75
3 additions, 0 deletions not shown
Dedicated Server Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
  • Blog
  • Support
  • Training
  • Job Board
  • Shop
  • Contact
  • API
  • Status
  • © 2010 GitHub Inc. All rights reserved.
  • Terms of Service
  • Privacy
  • Security
  • English
  • Deutsch
  • Français
  • 日本語
  • Português (BR)
  • Русский
  • 中文
  • See all available languages

Your current locale selection: English. Choose another?

  • English
  • Afrikaans
  • Català
  • Čeština
  • Deutsch
  • Español
  • Français
  • Hrvatski
  • Indonesia
  • Italiano
  • 日本語
  • Nederlands
  • Norsk
  • Polski
  • Português (BR)
  • Русский
  • Српски
  • Svenska
  • 中文

Keyboard Shortcuts

Site wide shortcuts

s
Focus site search
?
Bring up this help dialog

Commit list

j
Move selected down
k
Move selected up
t
Open tree
p
Open parent
c or o or enter
Open commit

Pull request list

j
Move selected down
k
Move selected up
o or enter
Open issue

Issues

j
Move selected down
k
Move selected up
x
Toggle select target
o or enter
Open issue
I
Mark selected as read
U
Mark selected as unread
e
Close selected
y
Remove selected from view
c
Create issue
l
Create label
i
Back to inbox
u
Back to issues
/
Focus issues search

Network Graph

← or h
Scroll left
→ or l
Scroll right
↑ or k
Scroll up
↓ or j
Scroll down
t
Toggle visibility of head labels
shift ← or shift h
Scroll all the way left
shift → or shift l
Scroll all the way right
shift ↑ or shift k
Scroll all the way up
shift ↓ or shift j
Scroll all the way down