Completed
Push — wip-locale ( 10edf9...34a478 )
by
unknown
02:18
created

CoreAdmin::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\CoreBundle\Admin;
14
15
use Sonata\AdminBundle\Datagrid\DatagridMapper;
16
use Sonata\AdminBundle\Datagrid\ListMapper;
17
use Sonata\AdminBundle\Form\FormMapper;
18
use Sonata\AdminBundle\Mapper\BaseMapper;
19
use Sonata\AdminBundle\Show\ShowMapper;
20
use Sonata\AdminBundle\Route\RouteCollection;
21
use Sonata\AdminBundle\Admin\AbstractAdmin as SonataAdmin;
22
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
23
use Blast\CoreBundle\Tools\Reflection\ClassAnalyzer;
24
use Blast\CoreBundle\Admin\Traits\CollectionsManager;
25
use Blast\CoreBundle\Admin\Traits\Mapper;
26
use Blast\CoreBundle\Admin\Traits\Templates;
27
use Blast\CoreBundle\Admin\Traits\PreEvents;
28
use Blast\CoreBundle\Admin\Traits\ManyToManyManager;
29
use Blast\CoreBundle\Admin\Traits\Actions;
30
use Blast\CoreBundle\Admin\Traits\ListActions;
31
use Blast\CoreBundle\CodeGenerator\CodeGeneratorRegistry;
32
use Blast\CoreBundle\Translator\LibrinfoLabelTranslatorStrategy;
33
use Symfony\Component\PropertyAccess\PropertyAccess;
34
35
abstract class CoreAdmin extends SonataAdmin implements \JsonSerializable
36
{
37
    use CollectionsManager,
38
        ManyToManyManager,
39
        Mapper,
40
        Templates,
41
        PreEvents,
42
        Actions,
43
        ListActions
44
    ;
45
46
    protected $extraTemplates = [];
47
48
        
49
    public function configure()
50
    {
51
        parent::configure();
52
53
        /* Default Translation Strategy if not set as admin service tags */
54
        /* @todo : find if it is a good idea or not */
55
        if (!($this->getLabelTranslatorStrategy() instanceof LibrinfoLabelTranslatorStrategy)) {
56
            $this->setLabelTranslatorStrategy(new LibrinfoLabelTranslatorStrategy());
57
        }
58
    }
59
    
60
    /**
61
     * Configure routes for list actions.
62
     *
63
     * @param RouteCollection $collection
64
     */
65
    protected function configureRoutes(RouteCollection $collection)
66
    {
67
        parent::configureRoutes($collection);
68
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
69
        $collection->add('generateEntityCode');
70
    }
71
72 View Code Duplication
    public function getBaseRouteName()
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...
73
    {
74
        $configuredBaseRoute = $this->getBaseRouteMapping();
75
76
        if (count($configuredBaseRoute) > 0) {
77
            $this->cachedBaseRouteName = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRouteName cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
78
            if (isset($configuredBaseRoute['name']) && $this->baseRouteName === null) {
79
                $this->baseRouteName = $configuredBaseRoute['name'];
80
            }
81
        }
82
83
        return parent::getBaseRouteName();
84
    }
85
86 View Code Duplication
    public function getBaseRoutePattern()
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...
87
    {
88
        $configuredBaseRoute = $this->getBaseRouteMapping();
89
90
        if (count($configuredBaseRoute) > 0) {
91
            $this->cachedBaseRoutePattern = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRoutePattern cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
92
            if (isset($configuredBaseRoute['pattern']) && $this->baseRoutePattern === null) {
93
                $this->baseRoutePattern = $configuredBaseRoute['pattern'];
94
            }
95
        }
96
97
        return parent::getBaseRoutePattern();
98
    }
99
100
    public function getFormTheme()
101
    {
102
        return array_merge($this->formTheme, $this->getFormThemeMapping());
103
    }
104
105
    /**
106
     * @param DatagridMapper $mapper
107
     */
108
    protected function configureDatagridFilters(DatagridMapper $mapper)
109
    {
110
        if (!$this->configureMapper($mapper)) {
111
            $this->fallbackConfiguration($mapper, __FUNCTION__);
112
        }
113
    }
114
115
    /**
116
     * @param ListMapper $mapper
117
     */
118
    protected function configureListFields(ListMapper $mapper)
119
    {
120
        if (!$this->configureMapper($mapper)) {
121
            $this->fallbackConfiguration($mapper, __FUNCTION__);
122
        }
123
    }
124
125
    /**
126
     * @param FormMapper $mapper
127
     */
128
    protected function configureFormFields(FormMapper $mapper)
129
    {
130
        if (!$this->configureMapper($mapper)) {
131
            $this->fallbackConfiguration($mapper, __FUNCTION__);
132
        }
133
    }
134
135
    /**
136
     * @param ShowMapper $mapper
137
     */
138
    protected function configureShowFields(ShowMapper $mapper)
139
    {
140
        if (!$this->configureMapper($mapper)) {
141
            $this->fallbackConfiguration($mapper, __FUNCTION__);
142
        }
143
    }
144
145
    /**
146
     * @param BaseMapper $mapper
147
     */
148
    protected function fixShowRoutes(BaseMapper $mapper)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    {
150
        foreach (['getShow', 'getList'] as $fct) {
151
            foreach ($this->$fct()->getElements() as $field) {
152
                if ($field instanceof FieldDescription) {
153
                    $options = $field->getOptions();
154
                    if ($options['route']['name'] != 'edit') {
155
                        continue;
156
                    }
157
158
                    $options['route']['name'] = 'show';
159
                    $field->setOptions($options);
160
                }
161
            }
162
        }
163
164
        return $this;
165
    }
166
167
    protected function getCurrentComposition()
168
    {
169
        // traits of the current Entity
170
        $classes = ClassAnalyzer::getTraits($this->getClass());
171
        // inheritance of the current Entity
172
        foreach (array_reverse([$this->getClass()] + class_parents($this->getClass())) as $class) {
173
            $classes[] = $class;
174
        }
175
        // inheritance of the current Admin
176
        foreach (array_reverse([$this->getOriginalClass()] + $this->getParentClasses()) as $admin) {
177
            $classes[] = $admin;
178
        }
179
180
        return $classes;
181
    }
182
183
    private function fallbackConfiguration(BaseMapper $mapper, $function)
184
    {
185
        // fallback
186
        $rm = new \ReflectionMethod($this->getParentClass(), $function);
187
        if ($rm->class == $this->getParentClass()) {
188
            $this->configureFields($function, $mapper, $this->getParentClass());
189
        }
190
    }
191
192
    /**
193
     * Returns the level of depth of an array.
194
     *
195
     * @param array $array
196
     * @param int   $level : do not use, just used for recursivity
197
     *
198
     * @return int : depth
199
     */
200
    private static function arrayDepth($array, $level = 0)
201
    {
202
        if (!$array) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $array of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
203
            return $level;
204
        }
205
206
        if (!is_array($array)) {
207
            return $level;
208
        }
209
210
        ++$level;
211
        foreach ($array as $key => $value) {
212
            if (is_array($value)) {
213
                $level = $level < self::arrayDepth($value, $level) ? self::arrayDepth($value, $level) : $level;
214
            }
215
        }
216
217
        return $level;
218
    }
219
220
    protected function getOriginalClass()
221
    {
222
        return get_called_class();
223
    }
224
225
    protected function getParentClasses()
226
    {
227
        return class_parents($this->getOriginalClass());
228
    }
229
230
    protected function getParentClass()
231
    {
232
        return get_parent_class($this->getOriginalClass());
233
    }
234
235
    protected function getGrandParentClass()
236
    {
237
        return get_parent_class(get_parent_class($this->getOriginalClass()));
238
    }
239
240
    /**
241
     * @param string $view     'list', 'show', 'form', etc
242
     * @param string $template template name
243
     */
244
    public function addExtraTemplate($view, $template)
245
    {
246
        if (empty($this->extraTemplates[$view])) {
247
            $this->extraTemplates[$view] = [];
248
        }
249
        if (!in_array($template, $this->extraTemplates[$view])) {
250
            $this->extraTemplates[$view][] = $template;
251
        }
252
    }
253
254
    /**
255
     * @param string $view 'list', 'show', 'form', etc
256
     *
257
     * @return array array of template names
258
     */
259
    public function getExtraTemplates($view)
260
    {
261
        if (empty($this->extraTemplates[$view])) {
262
            $this->extraTemplates[$view] = [];
263
        }
264
265
        return $this->extraTemplates[$view];
266
    }
267
268
    /**
269
     * @param string $view 'list', 'show', 'form', etc
270
     * @param array  $link link (array keys should be: 'label', 'url', 'class', 'title')
271
     */
272
    public function addHelperLink($view, $link)
273
    {
274
        if (empty($this->helperLinks[$view])) {
275
            $this->helperLinks[$view] = [];
276
        }
277
278
        // Do not add links without URL
279
        if (empty($link['url'])) {
280
            return;
281
        }
282
283
        // Do not add two links with the same URL
284
        foreach ($this->helperLinks[$view] as $l) {
285
            if ($l['url'] == $link['url']) {
286
                return;
287
            }
288
        }
289
290
        $this->helperLinks[$view][] = $link;
291
    }
292
293
    /**
294
     * @param string $view 'list', 'show', 'form', etc
295
     *
296
     * @return array array of links (each link is an array with keys 'label', 'url', 'class' and 'title')
297
     */
298
    public function getHelperLinks($view)
299
    {
300
        if (empty($this->helperLinks[$view])) {
301
            $this->helperLinks[$view] = [];
302
        }
303
304
        return $this->helperLinks[$view];
305
    }
306
307
    /**
308
     * Checks if a Bundle is installed.
309
     *
310
     * @param string $bundle Bundle name or class FQN
311
     */
312
    public function bundleExists($bundle)
313
    {
314
        $kernelBundles = $this->getConfigurationPool()->getContainer()->getParameter('kernel.bundles');
315
        if (array_key_exists($bundle, $kernelBundles)) {
316
            return true;
317
        }
318
        if (in_array($bundle, $kernelBundles)) {
319
            return true;
320
        }
321
322
        return false;
323
    }
324
325
    /**
326
     * Rename a form tab after form fields have been configured.
327
     *
328
     * TODO: groups of the renamed tab are still prefixed with the old tab name
329
     *
330
     * @param type $tabName    the name of the tab to be renamed
331
     * @param type $newTabName the new name for the tab
332
     */
333 View Code Duplication
    public function renameFormTab($tabName, $newTabName, $keepOrder = true)
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...
334
    {
335
        $tabs = $this->getFormTabs();
336
337
        if (!$tabs) {
338
            return;
339
        }
340
341
        if (!isset($tabs[$tabName])) {
342
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
343
        }
344
        if (isset($tabs[$newTabName])) {
345
            return;
346
        }
347
348
        if ($keepOrder) {
349
            $keys = array_keys($tabs);
350
            $keys[array_search($tabName, $keys)] = $newTabName;
351
            $tabs = array_combine($keys, $tabs);
352
        } else {
353
            $tabs[$newTabName] = $tabs[$tabName];
354
            unset($tabs[$tabName]);
355
        }
356
357
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 335 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
358
    }
359
360
    /**
361
     * Rename a show tab after show fields have been configured.
362
     *
363
     * TODO: groups of the renamed tab are still prefixed with the old tab name
364
     *
365
     * @param type $tabName    the name of the tab to be renamed
366
     * @param type $newTabName the new name for the tab
367
     */
368 View Code Duplication
    public function renameShowTab($tabName, $newTabName, $keepOrder = true)
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...
369
    {
370
        $tabs = $this->getShowTabs();
371
372
        if (!$tabs) {
373
            return;
374
        }
375
376
        if (!isset($tabs[$tabName])) {
377
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
378
        }
379
        if (isset($tabs[$newTabName])) {
380
            return;
381
        }
382
383
        if ($keepOrder) {
384
            $keys = array_keys($tabs);
385
            $keys[array_search($tabName, $keys)] = $newTabName;
386
            $tabs = array_combine($keys, $tabs);
387
        } else {
388
            $tabs[$newTabName] = $tabs[$tabName];
389
            unset($tabs[$tabName]);
390
        }
391
392
        $this->setShowTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getShowTabs() on line 370 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setShowTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
393
    }
394
395
    /**
396
     * Rename a form group.
397
     *
398
     * @param string $group        the old group name
399
     * @param string $tab          the tab the group belongs to
400
     * @param string $newGroupName the new group name
401
     *
402
     * @return self
403
     */
404
    public function renameFormGroup($group, $tab, $newGroupName)
405
    {
406
        $groups = $this->getFormGroups();
407
408
        // When the default tab is used, the tabname is not prepended to the index in the group array
409
        if ($tab !== 'default') {
410
            $group = $tab . '.' . $group;
411
        }
412
        $newGroup = ($tab !== 'default') ? $tab . '.' . $newGroupName : $newGroupName;
413
414
        if (isset($groups[$newGroup])) {
415
            throw new \Exception(sprintf('%s form group already exists.', $newGroup));
416
        }
417
        if (!array_key_exists($group, $groups)) {
418
            throw new \Exception(sprintf('form group « %s » doesn\'t exist.', $group));
419
        }
420
421
        $groups[$newGroup] = $groups[$group];
422
        $groups[$newGroup]['name'] = $newGroupName;
423
        unset($groups[$group]);
424
425
        $tabs = $this->getFormTabs();
426
        $key = array_search($group, $tabs[$tab]['groups']);
427
428
        if (false !== $key) {
429
            $tabs[$tab]['groups'][$key] = $newGroup;
430
        }
431
432
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 425 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
433
        $this->setFormGroups($groups);
0 ignored issues
show
Bug introduced by
It seems like $groups defined by $this->getFormGroups() on line 406 can also be of type boolean; however, Sonata\AdminBundle\Admin...tAdmin::setFormGroups() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
434
435
        return $this;
436
    }
437
438
    /**
439
     * Removes tab in current form Mapper.
440
     *
441
     * @param string|array $tabNames name or array of names of tabs to be removed
442
     * @param FormMapper   $mapper   Sonata Admin form mapper
443
     */
444
    public function removeTab($tabNames, $mapper)
445
    {
446
        $currentTabs = $this->getFormTabs();
447
        foreach ($currentTabs as $k => $item) {
0 ignored issues
show
Bug introduced by
The expression $currentTabs of type array|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...
448
            if (is_array($tabNames) && in_array($item['name'], $tabNames) || !is_array($tabNames) && $item['name'] === $tabNames) {
449
                foreach ($item['groups'] as $groupName) {
450
                    $this->removeAllFieldsFromFormGroup($groupName, $mapper);
451
                }
452
                unset($currentTabs[$k]);
453
            }
454
        }
455
        $this->setFormTabs($currentTabs);
0 ignored issues
show
Bug introduced by
It seems like $currentTabs defined by $this->getFormTabs() on line 446 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
456
    }
457
458
    /**
459
     * Removes all fields from form groups and remove them from mapper.
460
     *
461
     * @param string     $groupName Name of the group to remove
462
     * @param FormMapper $mapper    Sonata Admin form mapper
463
     */
464
    public function removeAllFieldsFromFormGroup($groupName, $mapper)
465
    {
466
        $formGroups = $this->getFormGroups();
467
        foreach ($formGroups as $name => $formGroup) {
0 ignored issues
show
Bug introduced by
The expression $formGroups of type array|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...
468
            if ($name === $groupName) {
469
                foreach ($formGroups[$name]['fields'] as $key => $field) {
470
                    $mapper->remove($key);
471
                }
472
            }
473
        }
474
    }
475
476
    public function jsonSerialize()
477
    {
478
        $propertiesToShow = [
479
            'baseRouteName',
480
            'baseRoutePattern',
481
            'extraTemplates',
482
            'listFieldDescriptions',
483
            'showFieldDescriptions',
484
            'formFieldDescriptions',
485
            'filterFieldDescriptions',
486
            'maxPerPage',
487
            'maxPageLinks',
488
            'classnameLabel',
489
            'translationDomain',
490
            'formOptions',
491
            'datagridValues',
492
            'perPageOptions',
493
            'pagerType',
494
            'code',
495
            'label',
496
            'routes',
497
            'subject',
498
            'children',
499
            'parent',
500
            'baseCodeRoute',
501
            'uniqid',
502
            'extensions',
503
            'class',
504
            'subClasses',
505
            'list',
506
            'show',
507
            'form',
508
            'filter',
509
            'formGroups',
510
            'formTabs',
511
            'showGroups',
512
            'showTabs',
513
            'managedCollections',
514
            'helperLinks',
515
            'titles',
516
        ];
517
518
        $properties = [];
519
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Blast\CoreBundle\Admin\CoreAdmin> is not traversable.
Loading history...
520
            if (in_array($key, $propertiesToShow)) {
521
                $properties[$key] = $value;
522
            }
523
        }
524
525
        return $properties;
526
    }
527
528
    /**
529
     * {@inheritdoc}
530
     */
531
    public function prePersist($object)
532
    {
533
        parent::prePersist($object);
534
535
        $hasCodeGenerator = CodeGeneratorRegistry::hasGeneratorForClass(get_class($object));
536
        if ($hasCodeGenerator) {
537
            $accessor = PropertyAccess::createPropertyAccessor();
538
            foreach (CodeGeneratorRegistry::getCodeGenerators(get_class($object)) as $name => $generator) {
539
                $accessor->setValue($object, $name, $generator->generate($object));
540
            }
541
        }
542
    }
543
}
544