1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LoadAppData Données de l'application GLSR. |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @author Quétier Laurent <[email protected]> |
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
10
|
|
|
* |
11
|
|
|
* @version GIT: <git_id> |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
14
|
|
|
*/ |
15
|
|
|
namespace AppBundle\DataFixtures\ORM; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
18
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
20
|
|
|
|
21
|
|
|
use libphonenumber\PhoneNumber; |
22
|
|
|
use AppBundle\Entity\Settings\Company; |
23
|
|
|
use AppBundle\Entity\Settings\Settings; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* LoadApp Data. |
27
|
|
|
* |
28
|
|
|
* @category DataFixtures |
29
|
|
|
*/ |
30
|
|
|
class LoadAppData extends AbstractFixture implements OrderedFixtureInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Load data fixtures with the passed EntityManager |
34
|
|
|
* |
35
|
|
|
* @param ObjectManager $manager |
36
|
|
|
*/ |
37
|
|
|
public function load(ObjectManager $manager) |
38
|
|
|
{ |
39
|
|
|
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
40
|
|
|
|
41
|
|
|
// Load Company |
42
|
|
|
$app = new Company(); |
43
|
|
|
$app->setName('Dev-Int') |
|
|
|
|
44
|
|
|
->setStatus('S.A.R.L.') |
45
|
|
|
->setAddress('2, rue de la chèvre') |
46
|
|
|
->setZipCode('75000') |
47
|
|
|
->setTown('Paris') |
48
|
|
|
->setPhone($phoneUtil->parse('0140000000', "FR")) |
49
|
|
|
->setFax($phoneUtil->parse('0140000000', "FR")) |
50
|
|
|
->setMail('[email protected]') |
51
|
|
|
->setContact('Ursule') |
52
|
|
|
->setGsm($phoneUtil->parse('0640000000', "FR")); |
53
|
|
|
|
54
|
|
|
$manager->persist($app); |
55
|
|
|
|
56
|
|
|
// Load Settings |
57
|
|
|
$settings = new Settings(); |
58
|
|
|
$settings->setInventoryStyle("zonestorage") |
59
|
|
|
->setCalculation("weighted") |
60
|
|
|
->setCurrency("EUR"); |
61
|
|
|
|
62
|
|
|
$manager->persist($settings); |
63
|
|
|
|
64
|
|
|
$manager->flush(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the order of this fixture |
69
|
|
|
* |
70
|
|
|
* @return integer |
71
|
|
|
*/ |
72
|
|
|
public function getOrder() |
73
|
|
|
{ |
74
|
|
|
return 3; |
75
|
|
|
} |
76
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: