PHP code example of neosrulez / neos-essentials

1. Go to this page and download the library: Download neosrulez/neos-essentials library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neosrulez / neos-essentials example snippets


use NeosRulez\Neos\Essentials\Service\UserService;

#[Flow\Inject]
protected UserService $userService;

$this->userService->createUser(string $email, string|null $password = null, string|null $role = null); # Create a new account and a new user. A separate user model abstracted from the AbstractUser.php model is 

use NeosRulez\Neos\Essentials\Service\MailService;

#[Flow\Inject]
protected MailService $mailService;

$this->mailService()->sendMail(string $packageName, string $fusionPathAndFileName, array $variables, string $subject, string $sender, string $recipient, string|bool $replyTo = false, string|bool $cc = false, string|bool $bcc = false, array $attachments = []);

# Real life example
$this->mailService()->sendMail(
    'Acme.Package', # Package name for the Fusion Files
    'Acme/Package/Mail/FusionMail', # Component Name of the Fusion Files
    ['foo' => 'foos', 'bar' => $variable], # Variables used in the mail
    'Welcome to the Neos Flow application!', # Subject of the mail
    '[email protected]', # Senders address
    $user->getEmail(), # Recipients address
    false, # In that case no reply to
    false, # In that case no cc
    false, # In that case no bcc
    ['/application/the_path_to_your_file1.pdf', '/application/the_path_to_your_file2.pdf'] # File paths to the files to be attached to the mail
);

use NeosRulez\Neos\Essentials\Domain\Model\AbstractModel;

$entity->getIdentifier();

$entity->getCreated(); # Returns a DateTime Object
$entity->getCreated('Y-m-d'); # Returns a string

use NeosRulez\Neos\Essentials\Domain\Model\AbstractUser;

$userEntity->getAccount(); # Returns the Neos Flow Account referenced by the user
$userEntity->isActive(); # Returns a boolean