gmajor / substrate-codec-php
PHP SCALE Codec for Substrate - v2.0
v1.1.2
2025-05-14 07:48 UTC
Requires
- php: >=8.0
- ext-gmp: *
- ext-json: *
- ext-sodium: *
- bitwasp/buffertools: dev-master
- phpoption/phpoption: 1.9.x-dev
Requires (Dev)
- phpunit/phpunit: ^5.7 || ^9.3.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2026-03-24 07:50:59 UTC
README
PHP SCALE Codec for Substrate - Version 2.0
Architecture Overview
Directory Structure
src/
├── Bytes/ # Byte manipulation utilities
│ └── ScaleBytes.php
├── Encoder/ # Encoder interfaces
│ └── EncoderInterface.php
├── Decoder/ # Decoder interfaces
│ └── DecoderInterface.php
├── Types/ # Type definitions and implementations
│ ├── ScaleType.php # PHP 8.2 enum for SCALE types
│ ├── TypeInterface.php # Core type interface
│ ├── AbstractType.php # Base type implementation
│ ├── TypeRegistry.php # Type registration and lookup
│ ├── TypeFactory.php # Type creation factory
│ ├── BoolType.php
│ └── NullType.php
├── Metadata/ # Metadata parsing (Phase 3)
├── Extrinsic/ # Extrinsic handling (Phase 3)
└── Exception/ # Exception classes
├── ScaleEncodeException.php
├── ScaleDecodeException.php
└── InvalidTypeException.php
tests/
├── Bytes/
│ └── ScaleBytesTest.php
└── Types/
├── ScaleTypeTest.php
└── TypeRegistryTest.php
Key Components
ScaleType Enum (PHP 8.2)
use Substrate\ScaleCodec\Types\ScaleType; $type = ScaleType::U32; $type->getByteSize(); // 4 $type->isUnsignedInt(); // true
TypeRegistry
use Substrate\ScaleCodec\Types\{TypeRegistry, BoolType}; $registry = new TypeRegistry(); $registry->register('bool', new BoolType($registry)); $boolType = $registry->get('bool');
ScaleBytes
use Substrate\ScaleCodec\Bytes\ScaleBytes; $bytes = ScaleBytes::fromHex('0x01020304'); $bytes->readBytes(2); // [1, 2] $bytes->remaining(); // 2 $bytes->toHex(); // '0x01020304'
Installation
composer require gmajor/substrate-codec-php
Requirements
- PHP 8.2+
- ext-gmp
- ext-json
- ext-sodium
License
MIT License