1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LoadSupplierData Datas of the suppliers of the GLSR application. |
4
|
|
|
* |
5
|
|
|
* PHP Version 7 |
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
|
|
|
* @see https://github.com/Dev-Int/glsr |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace App\DataFixtures; |
17
|
|
|
|
18
|
|
|
use App\Entity\Settings\Supplier; |
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
20
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
21
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
22
|
|
|
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Load Supplier Data. |
26
|
|
|
* |
27
|
|
|
* @category DataFixtures |
28
|
|
|
*/ |
29
|
|
|
class LoadSupplierData extends Fixture implements DependentFixtureInterface, FixtureGroupInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Load data fixtures with the passed EntityManager. |
33
|
|
|
* |
34
|
|
|
* @param ObjectManager $manager |
35
|
|
|
*/ |
36
|
|
|
public function load(ObjectManager $manager) |
37
|
|
|
{ |
38
|
|
|
// Serialization of phone numbers |
39
|
|
|
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
40
|
|
|
// References of logistics families |
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
|
|
|
|
46
|
|
|
// Datas of suppliers |
47
|
|
|
$datas = [ |
48
|
|
|
['name' => 'Davigel', 'address' => '12, rue du gel', 'zipCode' => 75001, |
49
|
|
|
'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000001', 'FR'), |
50
|
|
|
'fax' => $phoneUtil->parse('0140000001', 'FR'), |
51
|
|
|
'mail' => '[email protected]', 'contact' => 'David Gel', |
52
|
|
|
'gsm' => $phoneUtil->parse('0160000001', 'FR'), 'family' => $surgele, |
53
|
|
|
'delayDeliv' => 2, 'orderDate' => [2, 5], ], |
54
|
|
|
['name' => 'Davifrais', 'address' => '12, rue du frais', |
55
|
|
|
'zipCode' => 75001, 'town' => 'Paris', |
56
|
|
|
'phone' => $phoneUtil->parse('0140000002', 'FR'), |
57
|
|
|
'fax' => $phoneUtil->parse('0140000002', 'FR'), |
58
|
|
|
'mail' => '[email protected]', 'contact' => 'David Frais', |
59
|
|
|
'gsm' => $phoneUtil->parse('0160000002', 'FR'), 'family' => $frais, |
60
|
|
|
'delayDeliv' => 2, 'orderDate' => [2, 5], ], |
61
|
|
|
['name' => 'Davisec', 'address' => '12, rue du sec', 'zipCode' => 75001, |
62
|
|
|
'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000003', 'FR'), |
63
|
|
|
'fax' => $phoneUtil->parse('0140000003', 'FR'), |
64
|
|
|
'mail' => '[email protected]', 'contact' => 'David Sec', |
65
|
|
|
'gsm' => $phoneUtil->parse('0160000003', 'FR'), 'family' => $sec, |
66
|
|
|
'delayDeliv' => 3, 'orderDate' => [3], ], |
67
|
|
|
['name' => 'Loire Boissons', 'address' => '12, rue de la soif', |
68
|
|
|
'zipCode' => 75001, 'town' => 'Paris', |
69
|
|
|
'phone' => $phoneUtil->parse('0140000004', 'FR'), |
70
|
|
|
'fax' => $phoneUtil->parse('0140000004', 'FR'), |
71
|
|
|
'mail' => '[email protected]', 'contact' => 'David Sec', |
72
|
|
|
'gsm' => $phoneUtil->parse('0160000004', 'FR'), 'family' => $boissons, |
73
|
|
|
'delayDeliv' => 3, 'orderDate' => [5], ], |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
foreach ($datas as $key => $data) { |
77
|
|
|
$supplier = new Supplier(); |
78
|
|
|
$supplier->setName($data['name']) |
|
|
|
|
79
|
|
|
->setAddress($data['address']) |
80
|
|
|
->setZipCode($data['zipCode']) |
81
|
|
|
->setTown($data['town']) |
82
|
|
|
->setPhone($data['phone']) |
|
|
|
|
83
|
|
|
->setFax($data['fax']) |
|
|
|
|
84
|
|
|
->setMail($data['mail']) |
85
|
|
|
->setContact($data['contact']) |
86
|
|
|
->setGsm($data['gsm']) |
|
|
|
|
87
|
|
|
->setFamilyLog($data['family']) |
88
|
|
|
->setDelaydeliv($data['delayDeliv']) |
89
|
|
|
->setOrderdate($data['orderDate']); |
90
|
|
|
|
91
|
|
|
$manager->persist($supplier); |
92
|
|
|
$order = $key + 1; |
93
|
|
|
$this->addReference('supplier'.$order, $supplier); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$manager->flush(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getDependencies() |
100
|
|
|
{ |
101
|
|
|
return [LoadDiverseData::class]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public static function getGroups(): array |
105
|
|
|
{ |
106
|
|
|
return ['settingsGroup']; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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: