1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LoadSupplierData 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\Supplier; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Load Supplier Data. |
26
|
|
|
* |
27
|
|
|
* @category DataFixtures |
28
|
|
|
*/ |
29
|
|
|
class LoadSupplierData extends AbstractFixture implements OrderedFixtureInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Load data fixtures with the passed EntityManager |
33
|
|
|
* |
34
|
|
|
* @param ObjectManager $manager |
35
|
|
|
*/ |
36
|
|
|
public function load(ObjectManager $manager) |
37
|
|
|
{ |
38
|
|
|
// Serialisation des numéros de téléphone |
39
|
|
|
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
40
|
|
|
// Références des catégories |
41
|
|
|
$surgele = $this->getReference('family-log3'); |
42
|
|
|
$frais = $this->getReference('family-log4'); |
43
|
|
|
$sec = $this->getReference('family-log5'); |
44
|
|
|
$boissons = $this->getReference('family-log6'); |
45
|
|
|
// Datas des suppliers |
46
|
|
|
$datas =[ |
47
|
|
|
['name' => 'Davigel', 'address' => '12, rue du gel', 'zipCode' => 75001, |
48
|
|
|
'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000001', "FR"), |
49
|
|
|
'fax' => $phoneUtil->parse('0140000001', "FR"), |
50
|
|
|
'mail' => '[email protected]', 'contact' => 'David Gel', |
51
|
|
|
'gsm' => $phoneUtil->parse('0160000001', "FR"), 'family' => $surgele, |
52
|
|
|
'delayDeliv' => 2, 'orderDate' => [2, 5], ], |
53
|
|
|
['name' => 'Davifrais', 'address' => '12, rue du frais', |
54
|
|
|
'zipCode' => 75001, 'town' => 'Paris', |
55
|
|
|
'phone' => $phoneUtil->parse('0140000002', "FR"), |
56
|
|
|
'fax' => $phoneUtil->parse('0140000002', "FR"), |
57
|
|
|
'mail' => '[email protected]', 'contact' => 'David Frais', |
58
|
|
|
'gsm' => $phoneUtil->parse('0160000002', "FR"), 'family' => $frais, |
59
|
|
|
'delayDeliv' => 2, 'orderDate' => [2, 5], ], |
60
|
|
|
['name' => 'Davisec', 'address' => '12, rue du sec', 'zipCode' => 75001, |
61
|
|
|
'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000003', "FR"), |
62
|
|
|
'fax' => $phoneUtil->parse('0140000003', "FR"), |
63
|
|
|
'mail' => '[email protected]', 'contact' => 'David Sec', |
64
|
|
|
'gsm' => $phoneUtil->parse('0160000003', "FR"), 'family' => $sec, |
65
|
|
|
'delayDeliv' => 3, 'orderDate' => [3], ], |
66
|
|
|
['name' => 'Loire Boissons', 'address' => '12, rue de la soif', |
67
|
|
|
'zipCode' => 75001, 'town' => 'Paris', |
68
|
|
|
'phone' => $phoneUtil->parse('0140000004', "FR"), |
69
|
|
|
'fax' => $phoneUtil->parse('0140000004', "FR"), |
70
|
|
|
'mail' => '[email protected]', 'contact' => 'David Sec', |
71
|
|
|
'gsm' => $phoneUtil->parse('0160000004', "FR"), 'family' => $boissons, |
72
|
|
|
'delayDeliv' => 3, 'orderDate' => [5], ], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
foreach ($datas as $key => $data) { |
76
|
|
|
$supplier = new Supplier(); |
77
|
|
|
$supplier->setName($data['name']) |
|
|
|
|
78
|
|
|
->setAddress($data['address']) |
79
|
|
|
->setZipCode($data['zipCode']) |
80
|
|
|
->setTown($data['town']) |
81
|
|
|
->setPhone($data['phone']) |
|
|
|
|
82
|
|
|
->setFax($data['fax']) |
|
|
|
|
83
|
|
|
->setMail($data['mail']) |
84
|
|
|
->setContact($data['contact']) |
85
|
|
|
->setGsm($data['gsm']) |
|
|
|
|
86
|
|
|
->setFamilyLog($data['family']) |
87
|
|
|
->setDelaydeliv($data['delayDeliv']) |
88
|
|
|
->setOrderdate($data['orderDate']); |
89
|
|
|
|
90
|
|
|
$manager->persist($supplier); |
91
|
|
|
$order = $key + 1; |
92
|
|
|
$this->addReference('supplier' . $order, $supplier); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$manager->flush(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the order of this fixture |
100
|
|
|
* |
101
|
|
|
* @return integer |
102
|
|
|
*/ |
103
|
|
|
public function getOrder() |
104
|
|
|
{ |
105
|
|
|
return 5; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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: