EmailManager
extends Manager
in package
IMPORTANT: the front end module does not send e-mail.
This manager neither reads nor renders templates nor writes to the queue: it only passes the
data to the Api action :Api:System:Email:send and returns its Result. The front end
renders the form and sends the data; the Api decides whether an e-mail goes out.
IMPORTANT: do not bring back use SendEmailTrait. The removed shared trait had three flaws:
- it looked the template up via
findBy(key)=:Api:System:Email:getBy, an admin-only key, so underenforceit returned nothing andsendEmail()ended with false (the contact form, recommendation and advert lost-password sent nothing, silently); - with
email.sending.mode = 1(default) it calledsaveIntoEmailQueue(), which only the Api variant of the trait has, soNette\MemberAccessException(a descendant of\Errorin Nette 4) escapedcatch (\Exception)and a public form returned HTTP 500; - even if the method existed, the write would go to
:Api:System:EmailQueue:save, which is admin-only and cannot be opened (it is an external CRUD route, so it would allow foreign writes into the outgoing e-mail queue). All three disappear because the whole flow stays in the Api layer, whereEmailManagerhasEmailQueueManagerandsaveIntoEmailQueue()and calls them directly, without a guard.
Tags
Table of Contents
Properties
- $service : EmailService
- $appContext : AppContext
- $cacheTagInvalidator : CacheTagInvalidator|null
- Post-commit invalidator of the wire-payload query cache (tag bump per entity class).
- $languageContext : LanguageContext|null
- $paramsConfig : Config|null
- Neon parameters (`%params%`: server paths and directories), set by the decorator (`decorators.neon`) like `setAppContext()`.
- $presenterContext : PresenterContext
- $settingContext : SettingContext
Methods
- __construct() : mixed
- find() : SingleQuery<string|int, T>
- Finds one entity by ID and returns a `SingleQuery` object.
- findAll() : Query<string|int, T>
- Finds all entities and returns a `Query` object.
- findBy() : SingleQuery<string|int, T>
- Finds one entity by filters and returns a `SingleQuery` object.
- getAppContext() : AppContext
- getLanguageContext() : LanguageContext|null
- getPresenterContext() : PresenterContext
- getSettingContext() : SettingContext
- getSettings() : array<int, array<string, mixed>>
- getTotalCount() : int|null
- Returns the total count of the last `findAll()` of this manager's service, computed only when the query asked for it (`findAll(..., computeTotalCount: true)`); otherwise the last stored value.
- initializeAllContexts() : void
- sendEmail() : Result
- Asks the Api to send an e-mail from the template `$emailKey`.
- setAppContext() : $this
- setCacheTagInvalidator() : static
- setLanguageContext() : $this
- setParamsConfig() : static
- setPresenterContext() : $this
- setSettingContext() : $this
- bumpCacheTags() : void
- Bumps cache tags for the entity after commit: its class, the owned-cascade classes from metadata and the optional `additionalCacheTags()` of the manager.
- bumpCacheTagsExplicit() : void
- Bumps the given classes explicitly (raw-DBAL paths with a cross-entity effect).
- bumpCacheTagsForClass() : void
- Bumps cache tags by class name when there is no instance (bulk delete, `updateColumns()`, raw DBAL, tree operations).
- classCacheTags() : array<string|int, string>
- Returns extra tags for a bump that has no entity, typically tree operations ({@see \App\Core\Traits\Api\Models\Managers\TreeTrait::treeTransaction()}) that rewrite `lft`/`rgt` on many rows.
- getService() : TService
- Returns the service for the traits.
Properties
$service
public
EmailService
$service
$appContext
protected
AppContext
$appContext
$cacheTagInvalidator
Post-commit invalidator of the wire-payload query cache (tag bump per entity class).
protected
CacheTagInvalidator|null
$cacheTagInvalidator
= null
Set by the decorator (decorators.neon) like setParamsConfig(). Nullable and
fail-open: without wiring (or without Redis) a bump is a no-op.
$languageContext
protected
LanguageContext|null
$languageContext
= NULL
$paramsConfig
Neon parameters (`%params%`: server paths and directories), set by the decorator (`decorators.neon`) like `setAppContext()`.
protected
Config|null
$paramsConfig
= null
Write logic (asset directories) reads paths from here, not from getSettings() or the
setting context, which may be filled by the client without server paths. The property
cannot be named $config: it collides with the promoted $config in some managers.
$presenterContext
protected
PresenterContext
$presenterContext
$settingContext
protected
SettingContext
$settingContext
Methods
__construct()
public
__construct(EmailService $service) : mixed
Parameters
- $service : EmailService
find()
Finds one entity by ID and returns a `SingleQuery` object.
public
find(int $id[, string|array<string|int, mixed> $includes = [] ]) : SingleQuery<string|int, T>
Usage:
$query = $manager->find(1, ['translations']);
$entity = $query->include(['routes'])->execute(); // or ->get()
$title = $query->getTitle(); // magic call, forwarded to the entity
Parameters
- $id : int
-
entity ID
- $includes : string|array<string|int, mixed> = []
-
relations to load
['translations', 'routes'], or'*'for all
Return values
SingleQuery<string|int, T>findAll()
Finds all entities and returns a `Query` object.
public
findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBy = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, string|array<string|int, mixed> $includes = [] ][, bool $computeTotalCount = false ]) : Query<string|int, T>
Usage:
$query = $manager->findAll(['active' => true], ['created' => 'desc']);
$items = $query->include(['translations'])->limit(10)->execute();
foreach ($query as $item) { ... } // the query runs lazily on iteration
Parameters
- $filters : array<string|int, mixed>|null = []
-
filters for the where conditions
- $orderBy : array<string|int, mixed>|null = null
-
ordering
['column' => 'ASC/DESC'] - $offset : int|null = null
-
offset for pagination
- $limit : int|null = null
-
result limit
- $columns : array<string|int, mixed>|null = null
-
specific columns to load
- $includes : string|array<string|int, mixed> = []
-
relations to load
['translations', 'routes.translations'], or'*'for all - $computeTotalCount : bool = false
-
whether to compute the total count for pagination
Return values
Query<string|int, T>findBy()
Finds one entity by filters and returns a `SingleQuery` object.
public
findBy([array<string|int, mixed> $filters = [] ][, string|array<string|int, mixed> $includes = [] ]) : SingleQuery<string|int, T>
Usage:
$query = $manager->findBy(['slug' => 'my-page'], ['translations']);
$entity = $query->include(['routes'])->execute(); // or ->get()
$title = $query->getTitle(); // magic call, forwarded to the entity
Parameters
- $filters : array<string|int, mixed> = []
-
filters for the where conditions
- $includes : string|array<string|int, mixed> = []
-
relations to load
['translations', 'routes'], or'*'for all
Return values
SingleQuery<string|int, T>getAppContext()
public
getAppContext() : AppContext
Return values
AppContextgetLanguageContext()
public
getLanguageContext() : LanguageContext|null
Return values
LanguageContext|nullgetPresenterContext()
public
getPresenterContext() : PresenterContext
Return values
PresenterContextgetSettingContext()
public
getSettingContext() : SettingContext
Return values
SettingContextgetSettings()
public
getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>getTotalCount()
Returns the total count of the last `findAll()` of this manager's service, computed only when the query asked for it (`findAll(..., computeTotalCount: true)`); otherwise the last stored value.
public
getTotalCount() : int|null
Same value as Query::getTotalCount() of that query.
Return values
int|nullinitializeAllContexts()
public
initializeAllContexts() : void
sendEmail()
Asks the Api to send an e-mail from the template `$emailKey`.
public
sendEmail(int|null $langId, string $emailKey, string $toEmailAddrr[, array<string, mixed> $values = [] ][, array<int, string> $replyTos = [] ]) : Result
Compatible with the former SendEmailTrait::sendEmail() except: it returns Result, not
bool (the caller learns the failure reason), and it takes no attachments (File objects
do not pass the bridge). A flow that needs attachments should get its own Api action (as in
UserPresenter::internalActionSendNewPassword()).
Parameters
- $langId : int|null
- $emailKey : string
- $toEmailAddrr : string
- $values : array<string, mixed> = []
-
template parameters (texts, links)
- $replyTos : array<int, string> = []
Return values
ResultsetAppContext()
public
setAppContext(AppContext $appContext) : $this
Parameters
- $appContext : AppContext
Return values
$thissetCacheTagInvalidator()
public
setCacheTagInvalidator(CacheTagInvalidator $cacheTagInvalidator) : static
Parameters
- $cacheTagInvalidator : CacheTagInvalidator
Return values
staticsetLanguageContext()
public
setLanguageContext(LanguageContext|null $languageContext) : $this
Parameters
- $languageContext : LanguageContext|null
Return values
$thissetParamsConfig()
public
setParamsConfig(Config $paramsConfig) : static
Parameters
- $paramsConfig : Config
Return values
staticsetPresenterContext()
public
setPresenterContext(PresenterContext $presenterContext) : $this
Parameters
- $presenterContext : PresenterContext
Return values
$thissetSettingContext()
public
setSettingContext(SettingContext $settingContext) : $this
Parameters
- $settingContext : SettingContext
Return values
$thisbumpCacheTags()
Bumps cache tags for the entity after commit: its class, the owned-cascade classes from metadata and the optional `additionalCacheTags()` of the manager.
protected
bumpCacheTags(object $entity) : void
Fail-open (the invalidator swallows exceptions). Called from the manager Save/Delete/Tree traits after the commit.
Parameters
- $entity : object
bumpCacheTagsExplicit()
Bumps the given classes explicitly (raw-DBAL paths with a cross-entity effect).
protected
bumpCacheTagsExplicit(array<string|int, string> $classes) : void
Parameters
- $classes : array<string|int, string>
bumpCacheTagsForClass()
Bumps cache tags by class name when there is no instance (bulk delete, `updateColumns()`, raw DBAL, tree operations).
protected
bumpCacheTagsForClass(class-string $rootClass[, array<string|int, string> $extraTags = [] ]) : void
Bumps the root class and its owned-cascade classes.
Parameters
- $rootClass : class-string
- $extraTags : array<string|int, string> = []
classCacheTags()
Returns extra tags for a bump that has no entity, typically tree operations ({@see \App\Core\Traits\Api\Models\Managers\TreeTrait::treeTransaction()}) that rewrite `lft`/`rgt` on many rows.
protected
classCacheTags() : array<string|int, string>
IMPORTANT: additionalCacheTags(object) receives an entity, so a class-level bump cannot
use it; without this hook a delete would lose the cross-entity tag (Comment to
CommentThread). A manager whose cross-entity tag does not depend on a particular
entity returns it here.
NOTE: unlike additionalCacheTags(), this hook is declared (with an empty default)
instead of being an opt-in through method_exists(); method_exists() is always true in
a manager that has the method, which phpstan reports as alreadyNarrowedType.
Return values
array<string|int, string>getService()
Returns the service for the traits.
protected
getService() : TService