PHPackages                             iranimij/iranimij-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. iranimij/iranimij-core

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

iranimij/iranimij-core
======================

Iranimij shared foundation: serialization, config, filesystem helpers.

00PHP

Since May 7Pushed 1mo agoCompare

[ Source](https://github.com/iranimij/iranimij-core)[ Packagist](https://packagist.org/packages/iranimij/iranimij-core)[ RSS](/packages/iranimij-iranimij-core/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Iranimij\_Core
==============

[](#iranimij_core)

Shared foundation module for the Iranimij Magento 2 package family. Provides JSON serialization, typed configuration helpers, and media filesystem utilities — one canonical implementation used across all `iranimij/*` modules so the same logic is never duplicated.

Requirements
------------

[](#requirements)

RequirementVersionMagento2.4.6+PHP8.1+Installation
------------

[](#installation)

```
composer require iranimij/iranimij-core
bin/magento module:enable Iranimij_Core
bin/magento setup:upgrade
```

Provided Classes
----------------

[](#provided-classes)

### `Model\Serializer\JsonSerializer`

[](#modelserializerjsonserializer)

A thin, null-safe wrapper around Magento's `Serialize\Serializer\Json`. All modules in the Iranimij package use this class as the single JSON path — no direct `json_encode` / `json_decode` calls.

```
use Iranimij\Core\Model\Serializer\JsonSerializer;

// encode
$json = $serializer->encode(['key' => 'value']);   // '{"key":"value"}'

// decode with typed fallback — never throws
$data = $serializer->decode($json);                // ['key' => 'value']
$data = $serializer->decode(null);                 // null  (default fallback)
$data = $serializer->decode('bad', []);            // []    (fallback on parse error)

// guaranteed array return
$arr  = $serializer->decodeArray($json);           // ['key' => 'value']
$arr  = $serializer->decodeArray(null);            // []
$arr  = $serializer->decodeArray('bad');           // []
```

**Why not call `json_encode` directly?**
Magento's serializer respects `JSON_THROW_ON_ERROR` and the framework's encoding flags consistently. Using the wrapper also makes it trivial to swap the underlying implementation (e.g. for testing) via DI.

---

### `Model\Config\ConfigProviderAbstract`

[](#modelconfigconfigproviderabstract)

Base class for module-specific configuration providers. Extend it to get typed, scope-aware config getters without repeating the `ScopeConfigInterface` boilerplate.

```
use Iranimij\Core\Model\Config\ConfigProviderAbstract;

class MyModuleConfig extends ConfigProviderAbstract
{
    public function isEnabled(?int $storeId = null): bool
    {
        return $this->readFlag('mymodule/general/enabled', $storeId);
    }

    public function getApiKey(?int $storeId = null): string
    {
        return $this->readString('mymodule/general/api_key', $storeId);
    }

    public function getMaxItems(?int $storeId = null): int
    {
        return $this->readInt('mymodule/general/max_items', $storeId, 10);
    }

    public function getMultiplier(?int $storeId = null): float
    {
        return $this->readFloat('mymodule/general/multiplier', $storeId, 1.0);
    }
}
```

**Available methods** (all `protected`, all store-scoped):

MethodReturnDescription`readString($path, $storeId, $default)``string`Casts to string; returns `$default` if value is non-scalar.`readInt($path, $storeId, $default)``int`Casts numeric values to int; returns `$default` otherwise.`readFloat($path, $storeId, $default)``float`Casts numeric values to float; returns `$default` otherwise.`readFlag($path, $storeId)``bool`Delegates to `ScopeConfigInterface::isSetFlag`.All methods default to `SCOPE_STORE`. Pass `$storeId = null` to read from the current store context.

---

### `Service\Filesystem\MediaDirectoryProvider`

[](#servicefilesystemmediadirectoryprovider)

Wraps Magento's filesystem layer to expose the writable media directory with two helper methods.

```
use Iranimij\Core\Service\Filesystem\MediaDirectoryProvider;

// Get the writable WriteInterface for pub/media/
$write = $provider->writable();

// Ensure a sub-directory exists and return its absolute path
$absolutePath = $provider->ensureSubPath('mymodule/cache');
// → /var/www/html/pub/media/mymodule/cache  (created if missing)

// Resolve an absolute path without creating the directory
$absolutePath = $provider->relativeTo('mymodule/cache/file.png');
```

---

### `Service\Deploy\PubMediaResolver`

[](#servicedeploypubmediaresolver)

Combines `MediaDirectoryProvider` with Magento's `Filesystem\Io\File` to write content directly into `pub/media/`.

```
use Iranimij\Core\Service\Deploy\PubMediaResolver;

// Ensure the directory exists
$resolver->resolve('mymodule/generated');

// Write content to a file
$fullPath = $resolver->write('mymodule/generated', 'badge.png', $pngBinaryContent);
// → /var/www/html/pub/media/mymodule/generated/badge.png
```

---

### `Exception\InvalidConfigurationException`

[](#exceptioninvalidconfigurationexception)

A `LocalizedException` subclass for signalling that a module configuration value is missing or invalid. Throw it from config provider or service classes when a required setting is not present.

```
use Iranimij\Core\Exception\InvalidConfigurationException;
use Magento\Framework\Phrase;

if ($apiKey === '') {
    throw new InvalidConfigurationException(new Phrase('API key is not configured.'));
}
```

---

Running Tests
-------------

[](#running-tests)

```
# From the module directory
vendor/bin/phpunit -c phpunit.xml
```

Three unit-test classes ship with the module:

TestCoverage`JsonSerializerTest`encode/decode round-trip, null/empty fallback, malformed-JSON fallback, `decodeArray` always-array contract`ConfigProviderAbstractTest``readString`, `readInt`, `readFloat`, `readFlag` with valid values, non-scalar values, and defaults`MediaDirectoryProviderTest``writable()` delegation, `ensureSubPath` creation and idempotency, `relativeTo` path resolutionLicense
-------

[](#license)

[OSL-3.0](https://opensource.org/licenses/OSL-3.0)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance61

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31434218?v=4)[Iman Aboheydary](/maintainers/iranimij)[@iranimij](https://github.com/iranimij)

---

Top Contributors

[![iranimij](https://avatars.githubusercontent.com/u/31434218?v=4)](https://github.com/iranimij "iranimij (1 commits)")

### Embed Badge

![Health badge](/badges/iranimij-iranimij-core/health.svg)

```
[![Health](https://phpackages.com/badges/iranimij-iranimij-core/health.svg)](https://phpackages.com/packages/iranimij-iranimij-core)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
