You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/07.dependency-injection/04.adding-services/docs.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,21 @@ class MapBuilderService implements ServicesProviderInterface
62
62
63
63
[notice=tip]You'll notice that we've added `use UserFrosting\Sprinkle\Site\GoogleMaps\MapBuilder;` to the top of the file. This means that we don't have to use the fully qualified class name (with the entire namespace) every time we want to refer to the `MapBuilder` class.[/notice]
64
64
65
+
If you need to pull in another service, for example the config to retrieve an API key, you can add them as the parameter, and the dependency injector will automatically pick it up.
66
+
67
+
```php
68
+
...
69
+
MapBuilder::class => function (Config $config) {
70
+
$apiKey = $config['api.key'];
71
+
72
+
// Now, actually build the object
73
+
$mapBuilder = new MapBuilder($apiKey);
74
+
75
+
return $mapBuilder;
76
+
},
77
+
...
78
+
```
79
+
65
80
### Register your service
66
81
67
82
The next step is to tell UserFrosting to load your service in your [Sprinkle Recipe](/sprinkles/recipe#getservices). To do so, you only need to list all the service providers you want to automatically register inside the `$getServices` property of your sprinkle class :
Copy file name to clipboardExpand all lines: pages/14.database/04.seeding/docs.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ class MySeed implements SeedInterface
42
42
43
43
## Registering Seeds
44
44
45
-
To be picked up by the `seed` bakery command, a seed class files must first be registered in the the *Sprinkle Recipe*, using the `SeedRecipe` sub-recipe and the `getSeeds():array` method:
45
+
To be picked up by the `seed` bakery command, a seed class files must first be registered in the *Sprinkle Recipe*, using the `SeedRecipe` sub-recipe and the `getSeeds():array` method:
Copy file name to clipboardExpand all lines: pages/22.upgrading/01.46-to-50/02.guide/docs.md
+34-28Lines changed: 34 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,33 +6,33 @@ taxonomy:
6
6
category: docs
7
7
---
8
8
9
-
Upgrading an existing sprinkle from UserFrosting 4 to UserFrosting 5 can unfortunately be a difficult task. It all depends of how must customization of the core code you have done. Very basic sites will be easy to upgrade, very complex one could be a nightmare. However, it's for the greater good. UserFrosting 5 is more modern and uses new techniques
9
+
Upgrading an existing sprinkle from UserFrosting 4 to UserFrosting 5 can unfortunately be a difficult task. It all depends of how much customization of the core code you have done. Very basic sites will be easy to upgrade, very complex one could be a nightmare. However, it's for the greater good; UserFrosting 5 is more modern and uses new techniques.
10
10
11
-
[notice=warning]This guide contains the most important changes and action you need to take to upgrade your UserFrosting 4 Sprinkle. However, **it's far from complete**, as there are too many changes to document. Make sure you have a backup of your existing application and your **development database** before starting.
11
+
[notice=warning]This guide contains the most important changes and the actions you need to take to upgrade your UserFrosting 4 Sprinkle. However, **it's far from complete**, as there are too many changes to document. Make sure you have a backup of your existing application and your **development database** before starting.
12
12
13
13
If you spot anything missing, don't hesitate to contribute to this page via the [*edit this page*](https://github.com/userfrosting/learn/blob/5.1/pages/22.upgrading/01.46-to-50/02.guide/docs.md) button at the top.[/notice]
14
14
15
15
## Before you start
16
16
17
-
The upgrade path for your UserFrosting 4 sprinkle will depend on how many features you're using. The good new is, the database structure is the same, and the frontend is 90% the same.
17
+
The upgrade path for your UserFrosting 4 sprinkle will depend on how many features you're using. The good news is, the database structure is the same, and the frontend is 90% the same.
18
18
19
-
To begin the upgrade journey, **the first you should do is a [fresh install](/installation) of UserFrosting 5**. This is important, as it will allow you to familiarize yourself with the new structure, as well as validate that your [local development environment](/background/develop-locally-serve-globally) is up to date and meet the [minimum requirements](/installation/requirements).
19
+
To begin the upgrade journey, **the first you should do is a [fresh install](/installation) of UserFrosting 5**. This is important, as it will allow you to familiarize yourself with the new structure, as well as validate that your [local development environment](/background/develop-locally-serve-globally) is up to date and meets the [minimum requirements](/installation/requirements).
20
20
21
-
Once you have a functioning vanilla version of UserFrosting 5, you can begin upgrading your sprinkle.
21
+
Once you have a functioning vanilla version of UserFrosting 5, you can begin to upgrade your sprinkle.
22
22
23
23
[notice]While the database structure is mostly the same between V4 and V5, it is highly recommended you keep a backup of your existing application and your **development database**.[/notice]
24
24
25
25
## Upgrading your sprinkle structure
26
26
27
-
As seen on the [previous page](/upgrading/46-to-50/changelog), one of the biggest change is the app structure. It's recommended before you start to head over to [Chapter 3 - App Structure](/structure), to learn more about this new structure.
27
+
As seen on the [previous page](/upgrading/46-to-50/changelog), one of the biggest changes is the app structure. It's recommended before you start to head over to [Chapter 3 - App Structure](/structure), to learn more about this new structure.
28
28
29
-
Once you're familiar with the new structure, it's time to move thing around so your sprinkle meet the new structure. There's two options here: You can either start from scratch from the [Skeleton repo](/structure/introduction#the-app-skeleton-your-project-s-template), *or* you can manually upgrade in place.
29
+
Once you're familiar with the new structure, it's time to move thing around so your sprinkle meets the new structure. There's two options here: You can either start from scratch from the [Skeleton repo](/structure/introduction#the-app-skeleton-your-project-s-template), *or* you can manually upgrade in place.
30
30
31
31
The first option is easier as the base has been setup for you, and you can start right away moving your code into the skeleton created from the sprinkle template, in a new git repository. However, it's drawback is you'll probably lose your Git History. The second option is harder, but since you're starting from your existing code, you'll keep your git history if your code is saved on Github for example.
32
32
33
33
### Option 1 - Start over from the Skeleton
34
34
35
-
To start with this option, the first step is to create a [fresh install](/installation) from the app skeleton. You'll then have an empty sprinkle with the new structure, ready to copy your code into it. However there's some step you need to follow before going further.
35
+
To start with this option, the first step is to create a [fresh install](/installation) from the app skeleton. You'll then have an empty sprinkle with the new structure, ready to copy your code into it. However there's some steps you need to follow before going further.
36
36
37
37
#### Update `composer.json`
38
38
@@ -46,7 +46,7 @@ Once this is done, you can run `composer update` to fetch dependencies.
46
46
47
47
#### Edit the Recipe
48
48
49
-
Next up you should familiarize yourself with the [Sprinkle Recipe](/sprinkles/recipe#name). Right now, the only thing you must update is the sprinkle name, but we'll come back later to the recipe.
49
+
Next up, you should familiarize yourself with the [Sprinkle Recipe](/sprinkles/recipe#name). Right now, the only thing you must update is the sprinkle name, but we'll come back later to the recipe.
50
50
51
51
#### Moving your code
52
52
@@ -56,7 +56,7 @@ At this point you can skip to [Upgrading components](/upgrading/46-to-50/guide#u
56
56
57
57
### Option 2 - Upgrade in place
58
58
59
-
To start with this option, you should already be familiar with UserFrosting 5 directory structure, as it involves moving some directory around and editing some files. It also assume your code (your sprinkle) was located (and not as a community Sprinkle for example) You should have UserFrosting 5 Skeleton repo on hand to copy some files.
59
+
To start with this option, you should already be familiar with UserFrosting 5 directory structure, as it involves moving some directories around and editing some files. It also assumes your code (your sprinkle) was located (and not as a community sprinkle for example) You should have a UserFrosting 5 skeleton repo on hand to copy some files.
60
60
61
61
#### Moving files and directory
62
62
@@ -113,13 +113,13 @@ We'll update the rest of your recipe later.
113
113
114
114
#### The entry files
115
115
116
-
Finally, you'll need to update both *entry files*, aka `/bakery` and `/public/index.php`, with the correct reference to your recipe. Open both files, and replace `UserFrosting\App\MyApp` and `MyApp` with the correct reference to your recipe. See [this page](/sprinkles/customize#the-entry-files) for more information and example.
116
+
Finally, you'll need to update both *entry files*, aka `/bakery` and `/public/index.php`, with the correct reference to your recipe. Open both files, and replace `UserFrosting\App\MyApp` and `MyApp` with the correct reference to your recipe. See [this page](/sprinkles/customize#the-entry-files) for more information and examples.
117
117
118
118
## Upgrading components
119
119
120
-
At this point your UserFrosting 5 app is _kind of ready_ to work. You simply need to upgrade every component your use. The following list might contains stuff you're not using, but you should still go through them as they contains links and tip you may need later.
120
+
At this point your UserFrosting 5 app is _kind of ready_ to work. You simply need to upgrade every component you use. The following list might contain stuff you're not using, but you should still go through them as they contain links and tips you may need later.
121
121
122
-
Remember, this guide will give you only the big picture of what changed, pointing you to other part of the guide that goes in details with all the features.
122
+
Remember, this guide will give you only the big picture of what changed, but it will point you to the relevant parts of the documentation where more detail can be found.
123
123
124
124
### Global changes
125
125
@@ -135,7 +135,7 @@ Keep this in mind, especially if you've extended built-in classes. Not only may
135
135
136
136
### Services -> Dependency Injection
137
137
138
-
Services have been updated for UserFrosting 5. While the principle is the same, the way to register service is different. Services are now served by the new dependency injection container, PHP-DI. You should head over to the [Dependency Injection Chapter](/dependency-injection) to learn more about PHP-DI integration in UserFrosting 5 before going further.
138
+
Services have been updated for UserFrosting 5. While the principle is the same, the way to register a service is different. Services are now served by the new dependency injection container, PHP-DI. You should head over to the [Dependency Injection Chapter](/dependency-injection) to learn more about PHP-DI integration in UserFrosting 5 before going further.
139
139
140
140
Your services definition must first be updated to implement `UserFrosting\ServicesProvider\ServicesProviderInterface`. For example:
141
141
@@ -167,7 +167,7 @@ class ServicesProvider implements ServicesProviderInterface
167
167
168
168
You'll also need to **register your service** in your recipe. Checkout [Adding Services](/dependency-injection/adding-services) for more information.
169
169
170
-
Finally, instead or injecting the whole container and retrieving your service from it, your should inject the service directly into the class using [autowiring](/dependency-injection/the-di-container#autowiring) in the class constructor or thought [route service injection](/routes-and-controllers/controller-classes#service-injection) for example.
170
+
Finally, instead of injecting the whole container and retrieving your service from it, you should inject the service directly into the class using [autowiring](/dependency-injection/the-di-container#autowiring) in the class constructor or thought [route service injection](/routes-and-controllers/controller-classes#service-injection) for example.
171
171
172
172
For example:
173
173
@@ -193,32 +193,38 @@ The classmapper has been removed in UF5. PHP-DI should be used instead, via the
193
193
194
194
### Migrations
195
195
196
-
Migration are mostly the same, only the class structure as changed, as well as the need to register migration in your Sprinkle Recipe. The key points regarding migration are as follow:
196
+
Migrations are mostly the same, only the class structure as changed, as well as the need to register migration in your Sprinkle Recipe. The key points regarding migration are as follow:
197
197
198
-
1. Up/Down return type : The `up()` and `down()` method [must now return `void`](/database/migrations#base-class)
198
+
1. Up/Down return type : The `up()` and `down()` method [must now have a return type of`void`](/database/migrations#base-class)
199
199
200
-
2.Migration must [now implement](/database/migrations#base-class)`UserFrosting\Sprinkle\Core\Database\Migration`. Change `use UserFrosting\System\Bakery\Migration;` to `use UserFrosting\Sprinkle\Core\Database\Migration;` in every one of your migrations.
200
+
2.Migrations must [now extend](/database/migrations#base-class)`UserFrosting\Sprinkle\Core\Database\Migration`. Change `use UserFrosting\System\Bakery\Migration;` to `use UserFrosting\Sprinkle\Core\Database\Migration;` in every one of your migrations.
201
201
202
202
3.[Dependencies](/database/migrations#dependencies) must now be declared in a static property. Change `public $dependencies = [];` to `public static $dependencies = [];` in every one of your migrations.
203
203
204
-
4. Migration are not auto-discovered anymore. You need to add them to your sprinkle recipe, using `MigrationRecipe`. See [the migration chapter](/database/migrations#sprinkle-recipe) for more information and a detailed guide.
204
+
4. Migrations are not auto-discovered anymore. You need to add them to your sprinkle recipe, using `MigrationRecipe`. See [the migration chapter](/database/migrations#sprinkle-recipe) for more information and a detailed guide.
205
+
206
+
### Seeds
207
+
208
+
Seeds are also mostly the same, they just need to implement `\UserFrosting\Sprinkle\Core\Seeder\SeedInterface`, and have a `run()` function with a return type of `void`. They are also not auto-discovered, so need to be added to your sprinkle recipe using `SeedRecipe`.
209
+
210
+
See [the seeding chapter](/database/seeding) for more details.
205
211
206
212
### Models
207
213
208
214
The only change in database model is the `$timestamps` property is not `true` by default. It used to be `false`. ` public $timestamps = true;` can be removed from your models, unless you're **not** using timestamps where you should add `public $timestamps = false;`.
209
215
210
216
### Routes
211
217
212
-
The way to register route as changed. The definition is mostly the same, however the routes are now a real PHP classes, instead of static php resources. Check out the [Registering routes](/routes-and-controllers/registering-routes) guide for more information.
218
+
The way to register routes has changed. The definition is mostly the same, however the routes are now real PHP classes, instead of static php resources. Check out the [Registering routes](/routes-and-controllers/registering-routes) guide for more information.
213
219
214
-
To updated your routes, you should start by:
220
+
To updated your routes, you should start by:
215
221
216
222
1. Move your routes from `app/routes/*` to `app/src/Routes/*`;
217
223
2. Update your routes definitions so it's a class [implementing RouteDefinitionInterface](/routes-and-controllers/registering-routes)
218
224
3. Register your routes in your Sprinkle Recipe.
219
225
220
-
A few other key point to know:
221
-
1.Route groups definition has changed. See [Slim Documentation](https://www.slimframework.com/docs/v4/objects/routing.html#route-groups) for more information
226
+
A few other key points to know:
227
+
1.Definitions for route groups has changed. See [Slim Documentation](https://www.slimframework.com/docs/v4/objects/routing.html#route-groups) for more information
222
228
2. Controller resolution should be updated to make use of [PHP’s `::class` operator](https://www.slimframework.com/docs/v4/objects/routing.html#container-resolution)
223
229
3. Middleware must now be called by their class name. For example, `authGuard` must be updated to `UserFrosting\Sprinkle\Account\Authenticate\AuthGuard::class`
224
230
@@ -260,21 +266,21 @@ This also mean the **Classmapper** is not available anymore in sprunjes. You sho
260
266
261
267
### Controllers
262
268
263
-
Simple changes have been made to controller classes:
269
+
Simple changes have been made to controller classes:
264
270
265
271
1. Remove `extends SimpleController`, no extension is required anymore.
266
272
2.`use Slim\Http\Request;` must be changed to `use Psr\Http\Message\ServerRequestInterface as Request;`
267
273
3.`use Slim\Http\Response;` must be changed to `use Psr\Http\Message\ResponseInterface as Response;`
268
-
4. Since the DI container is not available globally in controllers, the services you requires must be [injected in constructor](/routes-and-controllers/controller-classes#service-injection)
274
+
4. Since the DI container is not available globally in the controllers, the services you require must be [injected via the constructor](/routes-and-controllers/controller-classes#service-injection)
269
275
1. For example, to use the `view` service, inject `Slim\Views\Twig;`
270
276
271
277
See [Controller classes](/routes-and-controllers/controller-classes) guide for more information.
272
278
273
-
[note]If your sprinkle extends a controller class from a default sprinkle instead of `SimpleController`, note that **every** controller classes from default sprinkles have been moved, renamed and rewritten as *Action classes*. Make sure to check out the sprinkle source code to find out how to update your sprinkle.[/note]
279
+
[note]If your sprinkle extends a controller class from a default sprinkle instead of `SimpleController`, note that **every** controller class from the default sprinkles have been moved, renamed and rewritten as *Action classes*. You will need to check out the sprinkle source code to find out how to update your sprinkle.[/note]
274
280
275
281
### Bakery
276
282
277
-
Simple changes have been made to bakery commands:
283
+
Simple changes have been made to bakery commands:
278
284
279
285
1. Command must extend `Symfony\Component\Console\Command\Command` instead of `UserFrosting\System\Bakery\BaseCommand`
280
286
2. Service should be injected through the class constructor (don't forget to call the parent constructor) or via [attribute injection](https://php-di.org/doc/attributes.html#inject).
@@ -287,7 +293,7 @@ Also note that the `create-admin` command has been renamed `create:admin-user`.
287
293
288
294
### Resources Stream / Locator
289
295
290
-
Not must as changed regarding the Resource Locator. Refer to the [Locator Service](/advanced/locator) page for more information. Note however that the two stream below have been renamed:
296
+
Not must has changed regarding the Resource Locator. Refer to the [Locator Service](/advanced/locator) page for more information. Note however that the two streams below have been renamed:
0 commit comments