Skip to content

Commit 1af26b2

Browse files
authored
Merge pull request #147 from archey347/hotfix
Add some stuff to the v4 -> v5.0 upgrade guide, Fix typos
2 parents c81670f + 28a9f1a commit 1af26b2

5 files changed

Lines changed: 73 additions & 38 deletions

File tree

  • pages
    • 07.dependency-injection/04.adding-services
    • 08.routes-and-controllers/04.controller-classes
    • 14.database/04.seeding
    • 22.upgrading

pages/07.dependency-injection/04.adding-services/docs.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ class MapBuilderService implements ServicesProviderInterface
6262

6363
[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]
6464

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+
6580
### Register your service
6681

6782
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 :

pages/08.routes-and-controllers/04.controller-classes/docs.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace UserFrosting\Sprinkle\Site\Controller;
2222

2323
use UserFrosting\Sprinkle\Site\Model\Owl;
2424

25+
use Psr\Http\Message\ResponseInterface as Response;
26+
use Psr\Http\Message\ServerRequestInterface as Request;
27+
2528
class OwlController
2629
{
2730
public function getOwls(string $genus, Request $request, Response $response): Response
@@ -74,6 +77,9 @@ namespace UserFrosting\Sprinkle\Site\Controller;
7477
use UserFrosting\Sprinkle\Site\Model\Owl;
7578
use UserFrosting\Sprinkle\Site\Finder\VoleFinder;
7679

80+
use Psr\Http\Message\ResponseInterface as Response;
81+
use Psr\Http\Message\ServerRequestInterface as Request;
82+
7783
class OwlController
7884
{
7985
public function getOwls(string $genus, Request $request, Response $response, VoleFinder $voleFinder): Response
@@ -97,6 +103,9 @@ namespace UserFrosting\Sprinkle\Site\Controller;
97103
use UserFrosting\Sprinkle\Site\Model\Owl;
98104
use UserFrosting\Sprinkle\Site\Finder\VoleFinder;
99105

106+
use Psr\Http\Message\ResponseInterface as Response;
107+
use Psr\Http\Message\ServerRequestInterface as Request;
108+
100109
class OwlController
101110
{
102111
/**
@@ -148,6 +157,9 @@ namespace UserFrosting\Sprinkle\Site\Controller;
148157
use UserFrosting\Sprinkle\Site\Model\Owl;
149158
use UserFrosting\Sprinkle\Site\Finder\VoleFinder;
150159

160+
use Psr\Http\Message\ResponseInterface as Response;
161+
use Psr\Http\Message\ServerRequestInterface as Request;
162+
151163
class GetOwlsAction
152164
{
153165
public function __invoke(string $genus, Request $request, Response $response, VoleFinder $voleFinder): Response

pages/14.database/04.seeding/docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MySeed implements SeedInterface
4242

4343
## Registering Seeds
4444

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:
4646

4747
```php
4848
<?php

pages/22.upgrading/01.46-to-50/02.guide/docs.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ taxonomy:
66
category: docs
77
---
88

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.
1010

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.
1212

1313
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]
1414

1515
## Before you start
1616

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.
1818

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).
2020

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.
2222

2323
[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]
2424

2525
## Upgrading your sprinkle structure
2626

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.
2828

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.
3030

3131
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.
3232

3333
### Option 1 - Start over from the Skeleton
3434

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.
3636

3737
#### Update `composer.json`
3838

@@ -46,7 +46,7 @@ Once this is done, you can run `composer update` to fetch dependencies.
4646

4747
#### Edit the Recipe
4848

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.
5050

5151
#### Moving your code
5252

@@ -56,7 +56,7 @@ At this point you can skip to [Upgrading components](/upgrading/46-to-50/guide#u
5656

5757
### Option 2 - Upgrade in place
5858

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.
6060

6161
#### Moving files and directory
6262

@@ -113,13 +113,13 @@ We'll update the rest of your recipe later.
113113

114114
#### The entry files
115115

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.
117117

118118
## Upgrading components
119119

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.
121121

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.
123123

124124
### Global changes
125125

@@ -135,7 +135,7 @@ Keep this in mind, especially if you've extended built-in classes. Not only may
135135

136136
### Services -> Dependency Injection
137137

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.
139139

140140
Your services definition must first be updated to implement `UserFrosting\ServicesProvider\ServicesProviderInterface`. For example:
141141

@@ -167,7 +167,7 @@ class ServicesProvider implements ServicesProviderInterface
167167

168168
You'll also need to **register your service** in your recipe. Checkout [Adding Services](/dependency-injection/adding-services) for more information.
169169

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.
171171

172172
For example:
173173

@@ -193,32 +193,38 @@ The classmapper has been removed in UF5. PHP-DI should be used instead, via the
193193

194194
### Migrations
195195

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:
197197

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)
199199

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.
201201

202202
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.
203203

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.
205211

206212
### Models
207213

208214
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;`.
209215

210216
### Routes
211217

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.
213219

214-
To updated your routes, you should start by :
220+
To updated your routes, you should start by:
215221

216222
1. Move your routes from `app/routes/*` to `app/src/Routes/*`;
217223
2. Update your routes definitions so it's a class [implementing RouteDefinitionInterface](/routes-and-controllers/registering-routes)
218224
3. Register your routes in your Sprinkle Recipe.
219225

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
222228
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)
223229
3. Middleware must now be called by their class name. For example, `authGuard` must be updated to `UserFrosting\Sprinkle\Account\Authenticate\AuthGuard::class`
224230

@@ -260,21 +266,21 @@ This also mean the **Classmapper** is not available anymore in sprunjes. You sho
260266

261267
### Controllers
262268

263-
Simple changes have been made to controller classes :
269+
Simple changes have been made to controller classes:
264270

265271
1. Remove `extends SimpleController`, no extension is required anymore.
266272
2. `use Slim\Http\Request;` must be changed to `use Psr\Http\Message\ServerRequestInterface as Request;`
267273
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)
269275
1. For example, to use the `view` service, inject `Slim\Views\Twig;`
270276

271277
See [Controller classes](/routes-and-controllers/controller-classes) guide for more information.
272278

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]
274280

275281
### Bakery
276282

277-
Simple changes have been made to bakery commands :
283+
Simple changes have been made to bakery commands:
278284

279285
1. Command must extend `Symfony\Component\Console\Command\Command` instead of `UserFrosting\System\Bakery\BaseCommand`
280286
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`.
287293

288294
### Resources Stream / Locator
289295

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:
291297

292298
1. log -> logs
293299
2. session -> sessions

0 commit comments

Comments
 (0)