Default Services

As mentioned in the last section, each Sprinkle can set up its own services through a service provider class. The default core and account Sprinkles set up many services that are essential to UserFrosting's functionality. These classes can be found in the src/ServicesProvider/ subdirectories in each Sprinkle's directory.

Core Services


This service handles the alert message stream, sometimes known as "flash messages". See Section 9.6 for more information.


Constructs the AssetManager object (namespace UserFrosting\Assets\AssetManager), which is responsible for loading information about assets (Javascript, CSS, images, etc) required by each page and constructing the appropriate HTML tags. See Asset Management for more information.


This service handles requests for raw assets made to the application. It locates the appropriate file for a given url, and builds the response containing the contents of the asset, along with setting headers for MIME type and length.


Creates an instance of a Laravel Cache. See Chapter 16 for more information.


Constructs the CheckEnvironment object (namespace UserFrosting\Sprinkle\Core\Util\CheckEnvironment), which does some basic checks in a new UF installation to make sure that the minimum requirements are met, directory permissions are set, etc.


Constructs the ClassMapper object (namespace UserFrosting\Sprinkle\Core\Util\ClassMapper), which provides dynamic class mapping in your controllers and classes. See Advanced Dev Features for more information on dynamic class mapping.


Constructs a Repository object (namespace UserFrosting\Support\Repository\Repository), which processes and provides a merged repository for the configuration files across all loaded Sprinkles. Additionally, it imports the Dotenv to allow automagically loading environment variables from .env file.

The config service also builds the site.uri.public config variable from the component values specified in the configuration.


Constructs the CSRF Guard middleware, which mitigates cross-site request forgery attacks on your users. See Chapter 2 for more information on security features.


Sets up the database.


Monolog Logger object for sending debug print statements and data to logs/debug.log. Can also be accessed via the Debug facade.


Sets up a ExceptionHandlerManager object, which is used as a custom error handler for UF's Slim application. It then registers the custom handlers for HttpException, PDOException, and phpmailerException. See Chapter 16 for more information on custom exceptions and exception error handlers.


Monolog Logger object for sending non-fatal error information from custom error handlers to logs/userfrosting.log.


Provide access to factories for the rapid creation of test objects.


A UserFrosting\I18n\LocalePathBuilder instance that constructs an ordered list of files containing translations. These files are used to initialize the MessageTranslator object available in the translator service.


Creates an instance of Mailer (namespace UserFrosting\Sprinkle\Core\Mail\Mailer), which serves as a UF-compatible wrapper for a PHPMailer object.

See Chapter 14 for more information.


Monolog Logger object for sending detailed SMTP mail server information from the mailer service to logs/userfrosting.log. Mail logging will only occur if debug.smtp is set to true.


Implements Slim's Custom Not Found handler, causing the application to return a 404 not found page.


Monolog Logger object for logging successfully completed database queries to logs/userfrosting.log.


Overrides Slim's default router, replacing their Router object with a UserFrosting\Sprinkle\Core\Router object. Our custom Router class allows for routes to be overridden and redefined in Sprinkles.

See Chapter 9 for more information about defining routes.


Sets up UserFrosting's Session object (UserFrosting\Session\Session), which serves as a wrapper for the $_SESSION superglobal. Session will use file- or database-based storage for sessions, depending on your configuration setting for session.handler. Session handlers are provided by Laravel's session handlers, which implement PHP's SessionHandlerInterface.

Please note that when using file-based sessions, UserFrosting places sessions in its own /app/sessions directory instead of PHP's default session directory.

Use UserFrosting's session service ($container->session) instead of PHP's $_SESSION superglobal in your code for proper functionality.


Sets up an instance of ShutdownHandler (UserFrosting\Sprinkle\Core\Util\ShutdownHandler), which attempts to capture and log any fatal errors raised. It registers itself with PHP's register_shutdown_function.


Creates a Throttler object, which handles request throttling for different routes. This service will automatically register any throttling rules defined in the throttles key of your configuration.


Sets up the MessageTranslator object (UserFrosting\I18n\MessageTranslator) for translation, localization, and internationalization of your site's contents. See Chapter 16 for more information.


Sets up the Twig View object, which is implemented by the Slim Twig-View project. Turns on caching and/or debugging depending on the settings for cache.twig and debug.twig, respectively. Also registers the UserFrosting's CoreExtension extension (UserFrosting\Sprinkle\Core\Twig\CoreExtension), which provides some additional functions, filters, and global variables for UserFrosting.

See Templating with Twig for more information about Twig and the custom functions, filters, and variables that UserFrosting defines.

Account Services


The Account Sprinkle extends the core assets service, to add search paths for any assets loaded in a user's custom theme.


The Account Sprinkle extends the core classMapper service, and registers the following model identifiers:

Identifier Model
user UserFrosting\Sprinkle\Account\Database\Models\User
group UserFrosting\Sprinkle\Account\Database\Models\Group
role UserFrosting\Sprinkle\Account\Database\Models\Role
permission UserFrosting\Sprinkle\Account\Database\Models\Permission
activity UserFrosting\Sprinkle\Account\Database\Models\Activity
password_reset UserFrosting\Sprinkle\Account\Database\Models\PasswordReset
verification UserFrosting\Sprinkle\Account\Database\Models\Verification


The Account Sprinkle extends the core errorHandler service, to add the following custom exception handlers:

Exception Handler
UserFrosting\Support\Exception\ForbiddenException UserFrosting\Sprinkle\Account\Handler\ForbiddenExceptionHandler
UserFrosting\Sprinkle\Account\Authenticate\Exception\AuthExpiredException UserFrosting\Sprinkle\Account\Error\Handler\AuthExpiredExceptionHandler
UserFrosting\Sprinkle\Account\Authenticate\Exception\AuthCompromisedException UserFrosting\Sprinkle\Account\Error\Handler\AuthCompromisedExceptionHandler


The Account Sprinkle extends the core localePathBuilder service, to add search paths for any locale files loaded in a user's custom theme.


The Account Sprinkle extends the core view service, adding the AccountExtension Twig extension (UserFrosting\Sprinkle\Account\Twig\AccountExtension). This extension adds the following:

  • checkAccess: Twig wrapper for the authorizer service's checkAccess method.
  • current_user: Twig wrapper for the currentUser service.

The extended view also adds search paths for any template files loaded in a user's custom theme.


Creates an instance of Authenticator (UserFrosting\Sprinkle\Account\Authenticate\Authenticator), which handles authenticating and logging in users. See Chapter 7 for more information.


Sets up the AuthGuard middleware, which is bound to routes that require authentication to access ("protected routes"). See Chapter 7 for more information.


Monolog Logger object for logging detailed information about access control checks. See Chapter 7 for more information about access control. Note that access control checks will only be logged if debug.auth is set to true in the configuration.


Creates an instance of AuthorizationManager (UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager), which handles access control checks via the checkAccess method. This service also defines several default access condition callbacks. More information, and a complete list of default access condition callbacks, can be found in Chapter 7.


Sets up the User object (UserFrosting\Sprinkle\Account\Database\Models\User) for the currently logged-in user. If there is no logged-in user, it returns null. It also loads the locale and theme for the current user, if set.


Returns a callback that redirects the client when they attempt to perform certain guest actions, but they are already logged in. For example, if they attempt to visit the registration or login pages when they are already signed in, this service will be used to redirect them to an appropriate landing page.


Returns a callback that sets the UF-Redirect header in the response. This callback is automatically invoked in the AccountController::login method. The UF-Redirect header is used by client-side code to determine where to redirect a given user after they log in.


Sets up a PasswordResetRepository object (UserFrosting\Sprinkle\Account\Repository\PasswordResetRepository), which handles token creation, verification, and expiration for password reset requests.


Sets up a VerificationRepository object (UserFrosting\Sprinkle\Account\Repository\VerificationRepository), which handles token creation, verification, and expiration for new account verification requests.


Sets up a Monolog logger, which uses UserFrosting\Sprinkle\Account\Log\UserActivityDatabaseHandler and UserFrosting\Sprinkle\Account\Log\UserActivityProcessor to allow logging of user activities to the activities database table. By using Monolog, it makes it easy to swap other storage solutions such as redis or Elastic Search.

System services

There are a few services which are loaded outside of the Sprinkle system, in UserFrosting's UserFrosting\System\ServiceProvider service provider. These include:


An instance of RocketTheme\Toolbox\Event\EventDispatcher, which itself extends the Symfony EventDispatcher class. This is used by Sprinkles to hook into the application lifecycle.


An instance of RocketTheme's Uniform Resource Locator class, which provides a unified method of accessing Sprinkle entities via streams.

See Chapter 16 for more information.


An instance of RocketTheme\Toolbox\StreamWrapper\StreamBuilder, which registers custom streams (cache://, config://, templates://, etc) with PHP's stream wrapper system.


An instance of UserFrosting\System\Sprinkle\SprinkleManager. Handles registration of Sprinkle bootstrapper classes and the loading of Sprinkle resources when UserFrosting is initialized.