Skip to content

Commit

Permalink
Added @return for all services for easier documentation, part of #711
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Oct 16, 2018
1 parent 56cad27 commit fcc2bfc
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 19 deletions.
45 changes: 38 additions & 7 deletions app/sprinkles/account/src/ServicesProvider/ServicesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/
namespace UserFrosting\Sprinkle\Account\ServicesProvider;

use Birke\Rememberme\Authenticator as RememberMe;
use Illuminate\Database\Capsule\Manager as Capsule;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ErrorLogHandler;
use Interop\Container\ContainerInterface;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Http\Message\ResponseInterface as Response;
Expand All @@ -25,7 +23,6 @@
use UserFrosting\Sprinkle\Account\Repository\PasswordResetRepository;
use UserFrosting\Sprinkle\Account\Repository\VerificationRepository;
use UserFrosting\Sprinkle\Account\Twig\AccountExtension;
use UserFrosting\Sprinkle\Core\Facades\Debug;
use UserFrosting\Sprinkle\Core\Log\MixedFormatter;

/**
Expand All @@ -38,12 +35,14 @@ class ServicesProvider
/**
* Register UserFrosting's account services.
*
* @param Container $container A DI container implementing ArrayAccess and container-interop.
* @param ContainerInterface $container A DI container implementing ArrayAccess and container-interop.
*/
public function register($container)
public function register(ContainerInterface $container)
{
/**
* Extend the asset manager service to see assets for the current user's theme.
*
* @return \UserFrosting\Assets\Assets
*/
$container->extend('assets', function ($assets, $c) {

Expand All @@ -68,6 +67,8 @@ public function register($container)
* Extend the 'classMapper' service to register model classes.
*
* Mappings added: User, Group, Role, Permission, Activity, PasswordReset, Verification
*
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
*/
$container->extend('classMapper', function ($classMapper, $c) {
$classMapper->setClassMapping('user', 'UserFrosting\Sprinkle\Account\Database\Models\User');
Expand All @@ -84,6 +85,8 @@ public function register($container)
* Extends the 'errorHandler' service with custom exception handlers.
*
* Custom handlers added: ForbiddenExceptionHandler
*
* @return \UserFrosting\Sprinkle\Core\Error\ExceptionHandlerManager
*/
$container->extend('errorHandler', function ($handler, $c) {
// Register the ForbiddenExceptionHandler.
Expand All @@ -98,6 +101,7 @@ public function register($container)
/**
* Extends the 'localePathBuilder' service, adding any locale files from the user theme.
*
* @return \UserFrosting\I18n\LocalePathBuilder
*/
$container->extend('localePathBuilder', function ($pathBuilder, $c) {
// Add paths for user theme, if a user is logged in
Expand Down Expand Up @@ -125,6 +129,8 @@ public function register($container)
* Extends the 'view' service with the AccountExtension for Twig.
*
* Adds account-specific functions, globals, filters, etc to Twig, and the path to templates for the user theme.
*
* @return \Slim\Views\Twig
*/
$container->extend('view', function ($view, $c) {
$twig = $view->getEnvironment();
Expand Down Expand Up @@ -159,6 +165,8 @@ public function register($container)
* Authentication service.
*
* Supports logging in users, remembering their sessions, etc.
*
* @return \UserFrosting\Sprinkle\Account\Authenticate\Authenticator
*/
$container['authenticator'] = function ($c) {
$classMapper = $c->classMapper;
Expand All @@ -178,6 +186,8 @@ public function register($container)

/**
* Sets up the AuthGuard middleware, used to limit access to authenticated users for certain routes.
*
* @return \UserFrosting\Sprinkle\Account\Authenticate\AuthGuard
*/
$container['authGuard'] = function ($c) {
$authenticator = $c->authenticator;
Expand All @@ -188,6 +198,8 @@ public function register($container)
* Authorization check logging with Monolog.
*
* Extend this service to push additional handlers onto the 'auth' log stack.
*
* @return \Monolog\Logger
*/
$container['authLogger'] = function ($c) {
$logger = new Logger('auth');
Expand All @@ -208,6 +220,8 @@ public function register($container)
* Authorization service.
*
* Determines permissions for user actions. Extend this service to add additional access condition callbacks.
*
* @return \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager
*/
$container['authorizer'] = function ($c) {
$config = $c->config;
Expand Down Expand Up @@ -327,20 +341,29 @@ public function register($container)

/**
* Loads the User object for the currently logged-in user.
*
* @return \UserFrosting\Sprinkle\Account\Database\Models\User
*/
$container['currentUser'] = function ($c) {
$authenticator = $c->authenticator;

return $authenticator->user();
};

/**
* Password Hasher service
*
* @return \UserFrosting\Sprinkle\Account\Authenticate\Hasher
*/
$container['passwordHasher'] = function ($c) {
$hasher = new Hasher();
return $hasher;
};

/**
* Returns a callback that forwards to dashboard if user is already logged in.
*
* @return callable
*/
$container['redirect.onAlreadyLoggedIn'] = function ($c) {
/**
Expand All @@ -361,6 +384,8 @@ public function register($container)

/**
* Returns a callback that handles setting the `UF-Redirect` header after a successful login.
*
* @return callable
*/
$container['redirect.onLogin'] = function ($c) {
/**
Expand All @@ -380,7 +405,7 @@ public function register($container)
return $determineRedirectOnLogin($response)->withStatus(200);
}

/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $c->authorizer;

$currentUser = $c->authenticator->user();
Expand All @@ -395,6 +420,8 @@ public function register($container)

/**
* Repository for password reset requests.
*
* @return \UserFrosting\Sprinkle\Account\Repository\PasswordResetRepository
*/
$container['repoPasswordReset'] = function ($c) {
$classMapper = $c->classMapper;
Expand All @@ -406,6 +433,8 @@ public function register($container)

/**
* Repository for verification requests.
*
* @return \UserFrosting\Sprinkle\Account\Repository\VerificationRepository
*/
$container['repoVerification'] = function ($c) {
$classMapper = $c->classMapper;
Expand All @@ -419,6 +448,8 @@ public function register($container)
* Logger for logging the current user's activities to the database.
*
* Extend this service to push additional handlers onto the 'userActivity' log stack.
*
* @return \Monolog\Logger
*/
$container['userActivityLogger'] = function ($c) {
$classMapper = $c->classMapper;
Expand Down
16 changes: 9 additions & 7 deletions app/sprinkles/admin/src/ServicesProvider/ServicesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
*/
namespace UserFrosting\Sprinkle\Admin\ServicesProvider;

use Interop\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager;
use UserFrosting\Sprinkle\Core\Facades\Debug;

/**
* Registers services for the admin sprinkle.
Expand All @@ -23,14 +21,16 @@ class ServicesProvider
/**
* Register UserFrosting's admin services.
*
* @param Container $container A DI container implementing ArrayAccess and container-interop.
* @param ContainerInterface $container A DI container implementing ArrayAccess and container-interop.
*/
public function register($container)
public function register(ContainerInterface $container)
{
/**
* Extend the 'classMapper' service to register sprunje classes.
*
* Mappings added: 'activity_sprunje', 'group_sprunje', 'permission_sprunje', 'role_sprunje', 'user_sprunje'
*
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
*/
$container->extend('classMapper', function ($classMapper, $c) {
$classMapper->setClassMapping('activity_sprunje', 'UserFrosting\Sprinkle\Admin\Sprunje\ActivitySprunje');
Expand All @@ -47,6 +47,8 @@ public function register($container)
* Returns a callback that handles setting the `UF-Redirect` header after a successful login.
*
* Overrides the service definition in the account Sprinkle.
*
* @return callable
*/
$container['redirect.onLogin'] = function ($c) {
/**
Expand All @@ -62,11 +64,11 @@ public function register($container)
// Backwards compatibility for the deprecated determineRedirectOnLogin service
if ($c->has('determineRedirectOnLogin')) {
$determineRedirectOnLogin = $c->determineRedirectOnLogin;

return $determineRedirectOnLogin($response)->withStatus(200);
}

/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $c->authorizer;

$currentUser = $c->authenticator->user();
Expand Down
Loading

0 comments on commit fcc2bfc

Please sign in to comment.