P
P
pegas2019-11-16 22:49:34
MODX
pegas, 2019-11-16 22:49:34

Modx how to initialize fenom object in console?

I want to create a modifier for fenom through the console
I know how to do it through the plugin and the pdoToolsOnFenomInit event

<?php
/** @var modX $modx */
switch ($modx->event->name) {
    case 'pdoToolsOnFenomInit':
        /** @var Fenom $fenom
            Мы получаем переменную $fenom при его первой инициализации и можем вызывать его методы. 
            Например, добавим модификатор вывода имени домена сайта из произвольной ссылки.
        */
        $fenom->addModifier('myModif', function ($input) {
            return ($input + 2);
        });
        break;
}

but now I need it through the console, I can’t get the fenom object
Tried like this, but the error
<?php
include 'core/components/pdotools/vendor/fenom/fenom/src/Fenom.php';
$fenom = new Fenom();

$fenom->addModifier('mymodif2', function ($input) {
    return ($input + 5);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2019-11-21
@1PeGaS

You need to initialize pdoTools and then use fenom:

<?php
/** @var array $scriptProperties */
/** @var pdoFetch $pdoFetch */
$fqn = $modx->getOption('pdoFetch.class', null, 'pdotools.pdofetch', true);
$path = $modx->getOption('pdofetch_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true);
if ($pdoClass = $modx->loadClass($fqn, $path, false, true)) {
    $pdoFetch = new $pdoClass($modx, $scriptProperties);
} else {
    return false;
}
$pdoFetch->addTime('pdoTools loaded');

But I doubt that you will be able to create a modifier in the console. You can create it in the plugin and then use it in the console.
If you need it for debugging, then write any debugging information from the plugin to the error log:
$modx->log(1, 'test: ' . $test);
$modx->log(1, 'array: ' . print_r($array, 1));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question