Initialise the mail service.

@param array $config
16618
protected function initMail( array $config )
    {
        if ( isset( $config[ 'mail' ] ) )
        {
            if ( isset( $config[ 'mail' ][ 'class' ] ) )
            {
                $this->bindShared( 'RawPHP\RawMail\Contract\IMail', function () use ( $config )
                {
                    $class = $config[ 'mail' ][ 'class' ];

                    return new $class( $config );
                }
                );
            }
            else
            {
                $this->bindShared( 'RawPHP\RawMail\Contract\IMail', function () use ( $config )
                {
                    return new Mail( $config );
                }
                );
            }
        }
        else
        {
            $this->bindShared( 'RawPHP\RawMail\Contract\IMail', function ()
            {
                return new Mail();
            }
            );
        }

        $this->alias( 'RawPHP\RawMail\Contract\IMail', 'mail' );
    }
496787
public function initialize(array $config) {
        parent::initialize($config);

        // set request
        $this->ctrl = $this->getController();
        $this->cookies = (new CookieCollection())->createFromServerRequest($this->ctrl->getRequest());
    }
1010325
public function initialize(array $config)
    {
        $this->table('cms_menu_items');

        $this->belongsTo('Menus', [
            'className' => 'Wasabi/Cms.Menus'
        ]);

        $this->addBehavior('CounterCache', ['Menus' => ['menu_item_count']]);
        $this->addBehavior('Tree');
        $this->addBehavior('Timestamp');
    }
898316
public function initialize(array $config = [])
    {
        $this->config = $config;
        if (is_array($this->config)) {
            if (array_keys($this->config) !== range(0, count($this->config) - 1)) {
                if (isset($this->config['db']) && is_array($this->config['db'])) {
                    foreach ($this->config['db'] as $key => &$value) {
                        if (!isset($value['port'])) {
                            $value['port'] = 3306;
                        }

                        if (!isset($value['charset'])) {
                            $value['charset'] = 'utf8';
                        }
                    }
                }

                $this->config = array_merge($this->defaults, $this->config);
                if (is_array($this->get('app_name'))) {
                    $hostName = Container::get('request')->getHostName();
                    if (array_key_exists($hostName, $this->get('app_name'))) {
                        $appName = $this->get('app_name')[$hostName];
                    } else {
                        throw new ConfigException('Cannot find any app paths.');
                    }
                } else {
                    $appName = $this->get('app_name');
                }

                if (Container::get('request')->isCli()) {
                    $stack = debug_backtrace();
                    $firstFrame = $stack[count($stack) - 1];
                    $initialFile = $firstFrame['file'];
                    $appFullPath = realpath(dirname($initialFile) . '/../' . rtrim($appName, '/'));
                } else {
                    $appFullPath = realpath(realpath('.') . '/../' . rtrim($appName, '/'));
                }

                if (!$appFullPath && !defined('KOTORI_PHP_TEST_ENV')) {
                    throw new ConfigException('Cannot find your app directory (' . $appName . ').');
                }

                $this->config = array_merge([
                    'app_full_path' => $appFullPath,
                ], $this->config);
                $this->set('namespace_prefix', basename($this->get('app_full_path')) . '\\');
            }
        } else {
            throw new ConfigException('config is not an array');
        }

        return $this;
    }
588287
public function init( $config = NULL )
    {
        $this->mailer = new PHPMailer();

        foreach ( $config as $key => $value )
        {
            switch ( $key )
            {
                case 'from_email':
                    $this->mailer->From = $value;
                    break;

                case 'from_name':
                    $this->mailer->FromName = $value;
                    break;

                case 'is_html':
                    $this->mailer->isHTML( ( bool ) $value );
                    break;

                case 'smtp':
                    if ( !empty( $value ) )
                    {
                        // mark it as SMTP mail
                        $this->mailer->isSMTP();

                        $this->mailer->Host       = $value[ 'host' ];
                        $this->mailer->SMTPAuth   = $value[ 'auth' ];
                        $this->mailer->Username   = $value[ 'username' ];
                        $this->mailer->Password   = $value[ 'password' ];
                        $this->mailer->SMTPSecure = $value[ 'security' ];
                        $this->mailer->Port       = $value[ 'port' ];
                    }
                    break;

                case 'reply_to':
                    if ( !empty( $value ) )
                    {
                        $this->mailer->addReplyTo( $value[ 'email' ], $value[ 'name' ] );
                    }
                    break;

                default:
                    // do nothing
                    break;
            }
        }
    }
1059108
public function initialize(array $config) {
		$this->setDisplayField('type');
		$this->addBehavior('Timestamp', ['modified' => false]);
		if (static::isSearchEnabled()) {
			$this->addBehavior('Search.Search');
		}
		$this->ensureTables(['DatabaseLog.DatabaseLogs']);

		$callback = Configure::read('DatabaseLog.monitorCallback');
		if (!$callback) {
			return;
		}
		$this->getEventManager()->on('DatabaseLog.alert', $callback);
	}
72883
public function initTasks(array $config)
    {
        foreach ($config as $taskName => $taskConfig) {
            $this->initTask($taskName, $taskConfig);
        }
    }
877268
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->addBehavior('Qobo/Utils.Footprint');

        $config = (new ModuleConfig(
            ConfigType::MODULE(),
            App::shortName($config['className'], 'Model/Table', 'Table')
        ))->parseToArray();

        // Set trash behavior
        if (!isset($config['table']['trash']) || $config['table']['trash'] === true) {
            $this->addBehavior('Muffin/Trash.Trash');
        }

        // set display field from config
        if (isset($config['table']['display_field'])) {
            $this->setDisplayField($config['table']['display_field']);
        }

        $this->setAssociations();
    }
1341986
public function initialize(array $config)
    {
        $this->hasMany('BlockRegions', [
            'className' => 'Block.BlockRegions',
            'foreignKey' => 'block_id',
            'dependent' => true,
            'propertyName' => 'region',
        ]);
        $this->hasMany('Copies', [
            'className' => 'Block.Blocks',
            'foreignKey' => 'copy_id',
            'dependent' => true,
            'propertyName' => 'copies',
            'cascadeCallbacks' => true,
        ]);
        $this->belongsToMany('User.Roles', [
            'className' => 'User.Roles',
            'foreignKey' => 'block_id',
            'joinTable' => 'blocks_roles',
            'dependent' => false,
            'propertyName' => 'roles',
        ]);

        $this->addBehavior('Serializable', [
            'columns' => ['locale', 'settings']
        ]);
    }
738219
public function initialize(array $config)
    {
        $this->verifyConfig();

        $this->_table->hasMany($this->getConfig('associationAlias'), [
            'className' => 'Muffin/Tokenize.Tokens',
            'foreignKey' => 'foreign_key',
            'conditions' => [
                'foreign_alias' => $this->_table->getAlias(),
                'foreign_table' => $this->_table->getTable(),
            ],
            'dependent' => true,
        ]);
    }
790471
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('tokens');
        $this->setDisplayField('token');
        $this->setPrimaryKey('id');

        $usersClass = empty($config['usersClassOptions']) ? Configure::read('Tokens.usersClassOptions') : $config['usersClassOptions'];
        if ($usersClass) {
            $this->belongsTo('Users', $usersClass);

            if (!$this->Users->hasAssociation('tokens')) {
                $this->Users->hasMany('Tokens')->setForeignKey('user_id');
            }
        }
    }
809528
public function initialize(array $config)
    {
        $this->belongsToMany('Roles', [
            'className' => 'User.Roles',
            'joinTable' => 'users_roles',
            'through' => 'UsersRoles',
            'propertyName' => 'roles',
        ]);
        $this->addBehavior('Timestamp', [
            'events' => [
                'Model.beforeSave' => [
                    'created' => 'new',
                ],
                'Users.login' => [
                    'last_login' => 'always'
                ]
            ]
        ]);
        $this->addBehavior('Search.Searchable', [
            'fields' => function ($user) {
                $words = '';
                $words .= empty($user->name) ?: " {$user->name}";
                $words .= empty($user->username) ?: " {$user->username}";
                $words .= empty($user->email) ?: " {$user->email}";
                $words .= empty($user->web) ?: " {$user->web}";

                if (!empty($user->_fields)) {
                    foreach ($user->_fields as $vf) {
                        $words .= ' ' . trim($vf->value);
                    }
                }

                return $words;
            }
        ]);
        $this->addBehavior('Field.Fieldable');

        $this->addSearchOperator('created', 'Search.Date', ['field' => 'created']);
        $this->addSearchOperator('limit', 'Search.Limit');
        $this->addSearchOperator('email', 'Search.Generic', ['field' => 'email', 'conjunction' => 'auto']);
        $this->addSearchOperator('order', 'Search.Order', ['fields' => ['name', 'username', 'email', 'web']]);
    }
1295443
public function initialize(array $config) {
		parent::initialize($config);

		$this->addBehavior('Timestamp');
		if (Configure::read('Queue.isSearchEnabled') !== false && Plugin::isLoaded('Search')) {
			$this->addBehavior('Search.Search');
		}

		$this->belongsTo('WorkerProcesses', [
			'className' => 'Queue.QueueProcesses',
			'foreignKey' => false,
			'conditions' => [
				'WorkerProcesses.workerkey = QueuedJobs.workerkey',
			],
		]);
	}
287586
protected function initialize(array $config)
    {
        $this->swooleServer = $this->createSwooleServer($config);

        $this->configureDefaultServerSocket();

        $this->setOptions($config['options'] ?? []);

        $this->registerEventCallbacks($this->serverEvents);

        $this->events->dispatch(new Events\ServerCreated($this));
    }
373994
public function initialize(array $config): void
    {
        // Set default translations
        $this->config('translations', [
            'id' => __d('model_history', 'field.id'),
            'comment' => __d('model_history', 'field.comment'),
            'created' => __d('model_history', 'field.created'),
            'modified' => __d('model_history', 'field.modified')
        ]);

        $this->ModelHistory = TableRegistry::get('ModelHistory.ModelHistory');
        // Dynamically attach the hasMany relationship
        $this->_table->hasMany('ModelHistory.ModelHistory', [
            'conditions' => [
                'ModelHistory.model' => $this->_table->registryAlias()
            ],
            'order' => ['ModelHistory.revision DESC'],
            'foreignKey' => 'foreign_key',
            'dependent' => false
        ]);

        if (isset($config['ignoreFields'])) {
            $this->setConfig('ignoreFields', $config['ignoreFields'], false);
        }

        $singularUnderscoredTableName = Inflector::singularize(Inflector::underscore($this->_table->getAlias()));
        $allColumns = $this->_table->getSchema()->columns();

        foreach ($allColumns as $columnName) {
            if (in_array($columnName, $this->getConfig('ignoreFields'))) {
                continue;
            }

            $obfuscated = false;
            $searchable = true;
            $type = 'string';

            if (substr($columnName, -3) === '_id') {
                $singular = substr($columnName, 0, -3);
                $associationName = str_replace('_', '', Inflector::pluralize($singular));
                $association = $this->_table->association($associationName);
                if (!is_null($association)) {
                    switch ($association->type()) {
                        case $association::MANY_TO_MANY:
                            $type = 'association';
                            break;

                        case $association::ONE_TO_MANY:
                        case $association::MANY_TO_ONE:
                            $type = 'relation';
                            break;
                    }
                }
            } elseif (strpos($columnName, 'password') !== false) {
                $obfuscated = true;
                $searchable = false;
            } else {
                switch ($this->_table->getSchema()->columnType($columnName)) {
                    case 'boolean':
                        $type = 'bool';
                        break;
                    case 'json':
                        $type = 'hash';
                        break;
                    case 'integer':
                        $type = 'number';
                        break;
                    case 'datetime':
                        $type = 'date';
                        break;
                }
            }
            $translationIdentifier = $singularUnderscoredTableName . '.' . $columnName;

            $manualConfig = isset($config['fields'][$columnName]) ? $config['fields'][$columnName] : [];
            $columnConfig = Hash::merge([
                'name' => $columnName,
                'translation' => function () use ($translationIdentifier) {
                    return __($translationIdentifier);
                },
                'searchable' => $searchable,
                'saveable' => true,
                'obfuscated' => $obfuscated,
                'type' => $type
            ], $manualConfig);

            $this->setConfig('fields.' . $columnName, $columnConfig, false);
        }

        // fill the config array of fields not in the table schema with default values
        if (!empty($config['fields'])) {
            foreach ($config['fields'] as $columnName => $manualConfig) {
                if (!in_array($columnName, $allColumns)) {
                    if (empty($manualConfig['type'])) {
                        throw new Exception(
                            sprintf('ModelHistory config for field %s is missing a type.', $columnName)
                        );
                    }

                    $translationIdentifier = $singularUnderscoredTableName . '.' . $columnName;

                    $columnConfig = Hash::merge([
                        'name' => $columnName,
                        'translation' => function () use ($translationIdentifier) {
                            return __($translationIdentifier);
                        },
                        'searchable' => true,
                        'saveable' => true,
                        'obfuscated' => false,
                    ], $manualConfig);

                    $this->setConfig('fields.' . $columnName, $columnConfig, false);
                }
            }
        }

        parent::initialize($config);
    }
197528
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->dir     = Configure::read('Cms.docDir');
        $this->locale  = Configure::read('App.defaultLocale');
        $this->charset = Str::low(Configure::read('App.encoding'));
        $this->eol     = (Configure::read('debug')) ? PHP_EOL : '';
        $this->tab     = (Configure::read('debug')) ? Configure::read('Cms.lineTab') : '';
    }
1365715
private function ritaInitialize(array $config)
    {
        if ($this->hasField('created') || $this->hasField('modified')) {
			$this->addBehavior('Timestamp');
		}
        $this->addBehavior('Rita/Tools.Persian');
    }