Completed
Push — master ( baab7b...a09b8f )
by
unknown
62:27
created

BaseBuilder::getFieldsets()   C

Complexity

Conditions 13
Paths 24

Size

Total Lines 31

Duplication

Lines 14
Ratio 45.16 %

Importance

Changes 0
Metric Value
dl 14
loc 31
rs 6.6166
c 0
b 0
f 0
cc 13
nc 24
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Admingenerator\GeneratorBundle\Builder\Admin;
4
5
use Symfony\Component\DependencyInjection\Container;
6
use Admingenerator\GeneratorBundle\Builder\BaseBuilder as GenericBaseBuilder;
7
use Admingenerator\GeneratorBundle\Generator\Column;
8
use Admingenerator\GeneratorBundle\Generator\Action;
9
10
/**
11
 * Base builder generating php for actions.
12
 *
13
 * @author cedric Lombardot
14
 * @author Piotr Gołębiewski <[email protected]>
15
 * @author Stéphane Escandell <[email protected]>
16
 */
17
class BaseBuilder extends GenericBaseBuilder
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $columns = null;
23
24
    /**
25
     * @var array
26
     */
27
    protected $actions = null;
28
29
    /**
30
     * @var array
31
     */
32
    protected $objectActions = null;
33
34
    /**
35
     * @var string
36
     */
37
    protected $columnClass = 'Column';
38
39
    public function getBaseAdminTemplate()
40
    {
41
        return $this->getGenerator()->getBaseAdminTemplate();
42
    }
43
44
    /**
45
     * Return a list of columns from list.display.
46
     *
47
     * @return array
48
     */
49
    public function getColumns()
50
    {
51
        if (null === $this->columns) {
52
            $this->columns = array();
53
            $this->findColumns();
54
        }
55
56
        return $this->columns;
57
    }
58
59
    protected function addColumn(Column $column)
60
    {
61
        $this->columns[$column->getName()] = $column;
62
    }
63
64
    protected function findColumns()
65
    {
66
        foreach ($this->getDisplayColumns() as $columnName) {
0 ignored issues
show
Bug introduced by
The expression $this->getDisplayColumns() of type array|object|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
67
            $column = $this->createColumn($columnName, true);
68
69
            //Set the user parameters
70
            $this->addColumn($column);
71
        }
72
    }
73
74
    public function getColumnGroups()
75
    {
76
        $groups = array();
77
78
        foreach ($this->getColumns() as $column) {
79
            $groups = array_merge($groups, $column->getGroups());
80
        }
81
82
        return $groups;
83
    }
84
85
    /**
86
     * Creates new column instance.
87
     *
88
     * @param string $columnName The name of the column.
89
     * @param bool   $withForms  If true, add column form configuration.
90
     *
91
     * @return Column
92
     */
93
    protected function createColumn($columnName, $withForms = false)
94
    {
95
        $column = new $this->columnClass($columnName, array(
96
            /* used for more verbose error messages */
97
            'builder' => $this->getYamlKey(),
98
            'generator' => $this->getBaseGeneratorName(),
99
        ));
100
101
        //Set the user parameters
102
        $this->setUserColumnConfiguration($column);
103
104
        $column->setDbType($this->getFieldOption(
105
            $column,
106
            'dbType',
107
            $this->getFieldGuesser()->getDbType(
108
                $this->getVariable('model'),
109
                $columnName
110
            )
111
        ));
112
113
        $column->setManyToMany($this->getFieldGuesser()->getManyToMany($this->getVariable('model'), $columnName));
114
115
        $column->setSortType($this->getFieldGuesser()->getSortType($column->getDbType()));
116
117
        $column->setPrimaryKey($this->getFieldOption(
118
            $column,
119
            'primaryKey',
120
            $this->getFieldGuesser()->getPrimaryKeyFor(
121
                $this->getVariable('model'),
122
                $columnName
123
            )
124
        ));
125
126
        if ($withForms) {
127
            $column->setFormType($this->getFieldOption(
128
                $column,
129
                'formType',
130
                $this->getFieldGuesser()->getFormType(
131
                    $column->getDbType(),
132
                    $this->getVariable('model'),
133
                    $columnName
134
                )
135
            ));
136
137
            // We don't use $column->getDbType because filtered column
138
            // might be on a field from an association. So we need to
139
            // resolve the filtered field dbType (and not the column
140
            // one).
141
            $filteredFieldDbType = $this->getFieldGuesser()->getDbType(
142
                $this->getVariable('model'),
143
                $column->getFilterOn()
144
            );
145
146
            $column->setFilterType($this->getFieldOption(
147
                $column,
148
                'filterType',
149
                $this->getFieldGuesser()->getFilterType(
150
                    $filteredFieldDbType,
151
                    $this->getVariable('model'),
152
                    $column->getFilterOn()
153
                )
154
            ));
155
156
            if ($this->getYamlKey() === 'list') {
157
                // Filters
158
                $column->setFilterOptions($this->getFieldOption(
159
                    $column,
160
                    'filterOptions',
161
                    $this->getFieldOption(
162
                        $column,
163
                        'formOptions',
164
                        $this->getFieldGuesser()->getFilterOptions(
165
                            $column->getFilterType(),
166
                            $filteredFieldDbType,
167
                            $this->getVariable('model'),
168
                            $column->getFilterOn()
169
                        )
170
                    )
171
                ));
172
            } else {
173
                $column->setFormOptions($this->getFieldOption(
174
                    $column,
175
                    'formOptions',
176
                    $this->getFieldGuesser()->getFormOptions(
177
                        $column->getFormType(),
178
                        $column->getDbType(),
179
                        $this->getVariable('model'),
180
                        $columnName
181
                    )
182
                ));
183
            }
184
185
            $fields = $this->getVariable('fields', array());
186
            $fieldOptions = is_array($fields) && array_key_exists($column->getName(), $fields)
187
                ? $fields[$column->getName()]
188
                : array();
189
190
            if (array_key_exists('addFormOptions', $fieldOptions)) {
191
                $column->setAddFormOptions($fieldOptions['addFormOptions']);
192
            }
193
194
            if (array_key_exists('addFilterOptions', $fieldOptions)) {
195
                $column->setAddFilterOptions($fieldOptions['addFilterOptions']);
196
            } elseif (array_key_exists('addFormOptions', $fieldOptions)) {
197
                $column->setAddFilterOptions($fieldOptions['addFormOptions']);
198
            }
199
        }
200
201
        return $column;
202
    }
203
204
    protected function getColumnClass()
205
    {
206
        return $this->columnClass;
207
    }
208
209
    public function setColumnClass($columnClass)
210
    {
211
        return $this->columnClass = $columnClass;
212
    }
213
214
    /**
215
     * @param Column $column
216
     * @param string $optionName
217
     * @param string $default
218
     *
219
     * @return string
220
     */
221
    protected function getFieldOption(Column $column, $optionName, $default = null)
222
    {
223
        $optionsFields = $this->getVariable('fields', array());
224
        $options = is_array($optionsFields) && array_key_exists($column->getName(), $optionsFields) ? $optionsFields[$column->getName()] : array();
225
226
        return isset($options[$optionName]) ? $options[$optionName] : $default;
227
    }
228
229
    protected function setUserColumnConfiguration(Column $column)
230
    {
231
        $optionsFields = $this->getVariable('fields', array());
232
        $options = is_array($optionsFields) && array_key_exists($column->getName(), $optionsFields) ? $optionsFields[$column->getName()] : array();
233
234
        foreach ($options as $option => $value) {
235
            $column->setProperty($option, $value);
236
        }
237
    }
238
239
    public function getFieldGuesser()
240
    {
241
        return $this->getGenerator()->getFieldGuesser();
242
    }
243
244
    /**
245
     * @return array Display column names
246
     */
247
    protected function getDisplayColumns()
248
    {
249
        $display = $this->getVariable('display');
250
251
        // tabs
252 View Code Duplication
        if (null == $display || (is_array($display) && 0 == count($display))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
253
            $tabs = $this->getVariable('tabs');
254
255
            if (null != $tabs || (is_array($tabs) && 0 < count($tabs))) {
256
                $display = array();
257
258
                foreach ($tabs as $tab) {
259
                    $display = array_merge($display, $tab);
260
                }
261
            }
262
        }
263
264 View Code Duplication
        if (null == $display || (is_array($display) && 0 == count($display))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
265
            return $this->getAllFields();
266
        }
267
268
        if (isset($display[0])) {
269
            return $display;
270
        }
271
272
        //there is fieldsets
273
        $return = array();
274
275
        foreach ($display as $fieldset => $rows_or_fields) {
0 ignored issues
show
Bug introduced by
The expression $display of type object|integer|double|string|boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
276
            foreach ($rows_or_fields as $fields) {
277
                if (is_array($fields)) { //It s a row
278
                    $return = array_merge($return, $fields);
279
                } else {
280
                    $return[$fields] = $fields;
281
                }
282
            }
283
        }
284
285
        return $return;
286
    }
287
288
    /**
289
     * Retrieve all columns.
290
     *
291
     * @return array
292
     */
293
    protected function getAllFields()
294
    {
295
        return $this->getFieldGuesser()->getAllFields($this->getVariable('model'));
296
    }
297
298
    /**
299
     * @return array
300
     */
301
    public function getFieldsets()
302
    {
303
        $display = $this->getVariable('display');
304
305
        // tabs
306 View Code Duplication
        if (null == $display || (is_array($display) && 0 == count($display))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
307
            $tabs = $this->getVariable('tabs');
308
309
            if (null != $tabs || (is_array($tabs) && 0 < count($tabs))) {
310
                $display = array();
311
312
                foreach ($tabs as $tab) {
313
                    $display = array_merge($display, $tab);
314
                }
315
            }
316
        }
317
318 View Code Duplication
        if (null == $display || (is_array($display) && 0 == count($display))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
319
            $display = $this->getAllFields();
320
        }
321
322
        if (isset($display[0])) {
323
            $display = array('NONE' => $display);
324
        }
325
326
        foreach ($display as $fieldset => $rows_or_fields) {
0 ignored issues
show
Bug introduced by
The expression $display of type object|integer|double|string|boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
327
            $display[$fieldset] = $this->getRowsFromFieldset($rows_or_fields);
328
        }
329
330
        return $display;
331
    }
332
333
    protected function getRowsFromFieldset(array $rows_or_fields)
334
    {
335
        $rows = array();
336
337
        foreach ($rows_or_fields as $key => $field) {
338
            if (is_array($field)) { //The row is defined in yaml
339
                $rows[$key] = $field;
340
            } else {
341
                $rows[$key][] = $field;
342
            }
343
        }
344
345
        return $rows;
346
    }
347
348
    /**
349
     * Get columns for tab, fieldset, row or field.
350
     *
351
     * @param mixed $input
352
     *
353
     * @return array Array of columns.
354
     */
355
    public function getColumnsFor($input)
356
    {
357
        if (!is_array($input)) {
358
            $input = array($input);
359
        }
360
361
        $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($input));
362
363
        $fieldsNames = iterator_to_array($it, false);
364
365
        return array_intersect_key($this->getColumns(), array_flip($fieldsNames));
366
    }
367
368
    /**
369
     * Return a list of action from list.actions.
370
     *
371
     * @return array
372
     */
373
    public function getActions()
374
    {
375
        if (null === $this->actions) {
376
            $this->actions = array();
377
            $this->findActions();
378
        }
379
380
        return $this->actions;
381
    }
382
383
    protected function setUserActionConfiguration(Action $action)
384
    {
385
        $actions = $this->getVariable('actions', array());
386
        $builderOptions = is_array($actions) && array_key_exists($action->getName(), $actions) ? $actions[$action->getName()] : array();
387
388
        $globalOptions = $this->getGenerator()->getFromYaml(
389
            'params.actions.'.$action->getName(),
390
            array()
391
        );
392
393
        if (null !== $builderOptions) {
394
            foreach ($builderOptions as $option => $value) {
395
                $action->setProperty($option, $value);
396
            }
397
        } elseif (null !== $globalOptions) {
398
            foreach ($globalOptions as $option => $value) {
399
                $action->setProperty($option, $value);
400
            }
401
        }
402
403
        if ('generic' == $action->getType()) {
404
            // Let's try to get credentials from builder for consistency
405
            if ($credentials = $this->generator->getFromYaml(sprintf('builders.%s.params.credentials', $action->getName()))) {
406
                $action->setCredentials($credentials);
407
            }
408
        }
409
    }
410
411
    protected function addAction(Action $action)
412
    {
413
        $this->actions[$action->getName()] = $action;
414
    }
415
416 View Code Duplication
    protected function findActions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
417
    {
418
        foreach ($this->getVariable('actions', array()) as $actionName => $actionParams) {
419
            $action = $this->findGenericAction($actionName);
420
421
            if (!$action) {
422
                $action = $this->findObjectAction($actionName);
423
            }
424
425
            if (!$action) {
426
                $action = new Action($actionName);
427
            }
428
429
            if ($globalCredentials = $this->getGenerator()->getFromYaml('params.credentials')) {
430
                // If generator is globally protected by credentials
431
                // actions are also protected
432
                $action->setCredentials($globalCredentials);
433
            }
434
435
            $this->setUserActionConfiguration($action);
436
            $this->addAction($action);
437
        }
438
    }
439
440
    /**
441
     * Return a list of action from list.object_actions.
442
     *
443
     * @return array
444
     */
445
    public function getObjectActions()
446
    {
447
        if (null === $this->objectActions) {
448
            $this->objectActions = array();
449
            $this->findObjectActions();
450
        }
451
452
        return $this->objectActions;
453
    }
454
455 View Code Duplication
    protected function setUserObjectActionConfiguration(Action $action)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
456
    {
457
        $objectActions = $this->getVariable('object_actions', array());
458
        $builderOptions = is_array($objectActions) && array_key_exists($action->getName(), $objectActions)
459
            ? $objectActions[$action->getName()]
460
            : array();
461
462
        $globalOptions = $this->getGenerator()->getFromYaml(
463
            'params.object_actions.'.$action->getName(),
464
            array()
465
        );
466
467
        if (null !== $builderOptions) {
468
            foreach ($builderOptions as $option => $value) {
469
                $action->setProperty($option, $value);
470
            }
471
        } elseif (null !== $globalOptions) {
472
            foreach ($globalOptions as $option => $value) {
473
                $action->setProperty($option, $value);
474
            }
475
        }
476
    }
477
478
    protected function addObjectAction(Action $action)
479
    {
480
        $this->objectActions[$action->getName()] = $action;
481
    }
482
483 View Code Duplication
    protected function findObjectActions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
484
    {
485
        $objectActions = $this->getVariable('object_actions', array());
486
487
        foreach ($objectActions as $actionName => $actionParams) {
488
            $action = $this->findObjectAction($actionName);
489
            if (!$action) {
490
                $action = new Action($actionName);
491
            }
492
493
            if ($globalCredentials = $this->getGenerator()->getFromYaml('params.credentials')) {
494
                // If generator is globally protected by credentials
495
                // object actions are also protected
496
                $action->setCredentials($globalCredentials);
497
            }
498
499
            $this->setUserObjectActionConfiguration($action);
500
            $this->addObjectAction($action);
501
        }
502
    }
503
504 View Code Duplication
    public function findGenericAction($actionName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
505
    {
506
        $class = 'Admingenerator\\GeneratorBundle\\Generator\\Action\\Generic\\'
507
                .Container::camelize(str_replace('-', '_', $actionName).'Action');
508
509
        return (class_exists($class)) ? new $class($actionName, $this) : false;
510
    }
511
512 View Code Duplication
    public function findObjectAction($actionName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
513
    {
514
        $class = 'Admingenerator\\GeneratorBundle\\Generator\\Action\\Object\\'
515
                .Container::camelize(str_replace('-', '_', $actionName).'Action');
516
517
        return (class_exists($class)) ? new $class($actionName, $this) : false;
518
    }
519
520 View Code Duplication
    public function findBatchAction($actionName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
521
    {
522
        $class = 'Admingenerator\\GeneratorBundle\\Generator\\Action\\Batch\\'
523
                .Container::camelize(str_replace('-', '_', $actionName).'Action');
524
525
        return (class_exists($class)) ? new $class($actionName, $this) : false;
526
    }
527
528
    public function getBaseGeneratorName()
529
    {
530
        return $this->getGenerator()->getBaseGeneratorName();
531
    }
532
533
    public function getNamespacePrefixWithSubfolder()
534
    {
535
        return $this->getVariable('namespace_prefix')
536
               .($this->hasVariable('subfolder') ? '\\'.$this->getVariable('subfolder') : '');
537
    }
538
539
    public function getRoutePrefixWithSubfolder()
540
    {
541
        return str_replace('\\', '_', $this->getNamespacePrefixWithSubfolder());
542
    }
543
544
    public function getNamespacePrefixForTemplate()
545
    {
546
        return str_replace('\\', '', $this->getVariable('namespace_prefix'));
547
    }
548
549
    public function getBaseActionsRoute()
550
    {
551
        return ltrim(
552
            str_replace(
553
                '\\',
554
                '_',
555
                $this->getVariable('namespace_prefix')
556
                .(($this->hasVariable('subfolder')) ? '_'.$this->getVariable('subfolder') : '')
557
                .'_'.$this->getVariable('bundle_name')
558
                .'_'.$this->getBaseGeneratorName()
559
            ),
560
            '_' // fix routes in AppBundle without vendor
561
        );
562
    }
563
564
    public function getObjectActionsRoute()
565
    {
566
        return $this->getBaseActionsRoute().'_object';
567
    }
568
569
    /**
570
     * Get the PK column name.
571
     *
572
     * @return string parameter
573
     */
574
    public function getModelPrimaryKeyName()
575
    {
576
        return $this->getGenerator()->getFieldGuesser()->getModelPrimaryKeyName($this->getVariable('model'));
577
    }
578
579
    /**
580
     * Allow to add complementary strylesheets.
581
     *
582
     *
583
     * param:
584
     *   stylesheets:
585
     *     - path/css.css
586
     *     - { path: path/css.css, media: all }
587
     *
588
     * @return array
589
     */
590
    public function getStylesheets()
591
    {
592
        $parse_stylesheets = function ($params, $stylesheets) {
593
            foreach ($params as $css) {
594
                if (is_string($css)) {
595
                    $css = array(
596
                        'path' => $css,
597
                        'media' => 'all',
598
                    );
599
                }
600
601
                $stylesheets[] = $css;
602
            }
603
604
            return $stylesheets;
605
        };
606
607
        // From config.yml
608
        $stylesheets = $parse_stylesheets(
609
            $this->getGenerator()->getFromBundleConfig('stylesheets', array()), array()
610
        );
611
612
        // From generator.yml
613
        $stylesheets = $parse_stylesheets(
614
            $this->getVariable('stylesheets', array()), $stylesheets
615
        );
616
617
        return $stylesheets;
618
    }
619
620
    /**
621
     * Allow to add complementary javascripts.
622
     *
623
     *
624
     * param:
625
     *   javascripts:
626
     *     - path/js.js
627
     *     - { path: path/js.js }
628
     *     - { route: my_route, routeparams: {} }
629
     *
630
     * @return array
631
     */
632
    public function getJavascripts()
633
    {
634
        $self = $this;
635
        $parse_javascripts = function ($params, $javascripts) use ($self) {
636
            foreach ($params as $js) {
637
                if (is_string($js)) {
638
                    $js = array(
639
                        'path' => $js,
640
                    );
641
                } elseif (isset($js['route'])) {
642
                    $js = array(
643
                        'path' => $self->getGenerator()
644
                                        ->getRouter()
645
                                        ->generate($js['route'], $js['routeparams']),
646
                    );
647
                }
648
649
                $javascripts[] = $js;
650
            }
651
652
            return $javascripts;
653
        };
654
655
        // From config.yml
656
        $javascripts = $parse_javascripts(
657
            $this->getGenerator()->getFromBundleConfig('javascripts', array()), array()
658
        );
659
660
        // From generator.yml
661
        $javascripts = $parse_javascripts(
662
            $this->getVariable('javascripts', array()), $javascripts
663
        );
664
665
        return $javascripts;
666
    }
667
}
668