Within each sprinkle, you will find any or all of the following directories and files:
├── app/ ├── assets/ ├── cache/ ├── config/ ├── locale/ ├── logs/ ├── schema/ ├── src/ ├── Bakery/ ├── Controllers/ ├── Database/ ├── [...] ├── Routes/ ├── Sprunje/ └── YourSprinkle.php ├── storage/ ├── templates/ ├── tests/ └── .env ├── public/ ├── vendor/ ├── composer.json ├── package.json └── webpack.config.js
app/can actually be named whatever you want. All content of
app/src/can also be customized. However, the other directory inside
app/(or whatever you call it) should be named the same, to allow your sprinkle to overwrite other sprinkles resources.
Each of these directories corresponds to specific types of entities that make up your application. UserFrosting has different rules for how each type of entity can extend the entities of the same type loaded in previous Sprinkles. A brief description of each one is listed below.
composer.json file is primarily used in UserFrosting to map PHP classes, but as this is Composer, it can also be used to reference additional PHP libraries. The
type key in your sprinkle's
composer.json file should always be defined as a
userfrosting-sprinkle. This will make your sprinkles manageable by Composer itself later.
composer.json should also define the sprinkles this one depends on.
To download frontend dependencies, from the project root directory:
$ php bakery webpack
webpack.config.js file is used for defining asset entries, that can be referenced by templates. The advantage of using asset entries (as compared to referencing the specific files) is that multiple files can be quickly referenced by the name of their entries. In production the individual files in each bundle are merged by Webpack Encore, reducing the number of HTTP requests that need to be made and thus reducing client latency and server load. See Chapter 11 for more information about asset bundles.
cache directory is used by the Cache system to store the cached files. This directory is only required when the sprinkle is used a main Sprinkle.
config contains the configuration parameters for your Sprinkle. You can define configuration files for different environments (development, testing, production, etc). For each environment, the configuration files in each Sprinkle will be merged together at runtime. See Chapter 6 for more information.
locale directory contains translation files for your Sprinkle. Like configuration files, translation files simply return an associative array.
Just as with configuration files, UserFrosting will recursively merge translation files for the currently selected language(s) from each loaded Sprinkle. This means that each subsequently loaded Sprinkle can override translations from previous Sprinkles, or define new ones entirely.
See Chapter 16 for more information on UserFrosting's internationalization and localization system.
logs directory is used to store the UserFrosting debug logs. This directory is only required when the sprinkle is used a main Sprinkle.
schema directory contains the request schema for your Sprinkle. Schema files in other Sprinkles can be extended by using a custom loader.
src directory contains the (preferably) PSR-4 compatible PHP code for your Sprinkle. This directory will contain your controllers, database models, migrations, routes, service providers, data sprunjers, and any other custom classes that your Sprinkle uses. This is where your Sprinkle Recipe will be found.
app/src/can be customized and doesn't need to follow any strict convention.
storage directory is used to store files managed by Filesystem service. This directory is only required when the sprinkle is used a main Sprinkle.
To separate content and logic, UserFrosting uses the popular Twig templating engine. Since Twig has its own system for loading templates, UserFrosting builds upon this to allow overriding templates in Sprinkles. See Templating with Twig for more information on how Twig is integrated into UserFrosting.
test directory is similar to
/src, but for your Tests.
.env file is used to store your local environnement variables. This file is only required when the sprinkle is used a main Sprinkle.
public directory is the web server's document / web root. The
index.php in this directory serves as the front controller for all HTTP requests. This directory is only required when the sprinkle is used a main Sprinkle.
vendor directory is where all Composer dependency will be loaded.