src/Stdlib/Modules/std/__engine__/importing.primi.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
<?php

namespace Smuuf\Primi\Stdlib\Modules;

use \Smuuf\Primi\Context;
use \Smuuf\Primi\Values\AbstractValue;
use \Smuuf\Primi\Modules\NativeModule;

/**
 * Native '__engine__.importing' module.
 */
return new class extends NativeModule {

    /** Context instance. */
    private Context $ctx;

    public function execute(Context $ctx): array {

        $this->ctx = $ctx;

        return [
            'get_loaded' => [$this, 'get_loaded'],
        ];

    }

    /**
     * _**Only in [CLI](https://w.wiki/QPE)**_.
     *
     * Returns memory peak usage used by Primi _(engine behind the scenes)_ in
     * bytes.
     */
    public function get_loaded(): AbstractValue {

        $loaded = $this->ctx->getImporter()->getLoaded();

        // We want to return only information about module objects and not paths
        // they were loaded from, so strip that information (paths are keys) in
        // the dict returned from importer instance. Get rid of them.
        return AbstractValue::buildAuto($loaded);

    }

};