Skip to content

KaririCode-Framework/kariricode-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KaririCode Examples

PHP 8.4+ License: MIT ARFA 1.3 KaririCode Framework

Real-world PHP 8.4 examples for every library in the KaririCode Framework ecosystem.

33 example files Β· 4 libraries Β· 100% rule and feature coverage Β· all runnable with a single command.

Transformer Β· Sanitizer Β· Dotenv Β· ClassDiscovery Β· Running All


Overview

This monorepo contains runnable example projects for each KaririCode Framework library. Every example is:

  • βœ… Self-contained β€” has its own composer.json and vendor/
  • βœ… Commented β€” every parameter documented with !! PARAMETER REFERENCE blocks
  • βœ… Verified β€” all assertions pass, all rules demonstrated
  • βœ… ARFA 1.3 compliant β€” follows KaririCode architectural standards
kariricode-examples/
β”œβ”€β”€ transformer-example/       # 6 examples Β· 32 rules
β”œβ”€β”€ sanitizer-example/         # 6 examples Β· 33 rules
β”œβ”€β”€ dotenv-example/            # 8 examples Β· full v4 feature set
└── classdiscovery-example/    # 13 examples Β· all scanners & filters

πŸ”„ Transformer Example

Turning raw data into clean, structured values β€” 32 built-in transformation rules.

transformer-example/ Β· README

What it covers

# Example Highlights
01 user-profile.php #[Transform] attributes, String + Date + Brazilian rules, TransformationResult inspection
02 brazilian-documents.php CPF, CNPJ, CEP, phone β€” AttributeTransformer vs TransformerEngine
03 product-import.php Numeric, Data (5), Encoding (3) rules, TransformerConfiguration
04 data-pipeline.php Structure (5) rules, dot notation, inline rules, merge()
05 content-management.php Date (4) + Encoding (3), base64 round-trip, hash comparison
06 all-rules.php All 32 rules β€” smoke test with parameter reference

All 32 rules at a glance

Brazilian (4): cpf_to_digits  cnpj_to_digits  cep_to_digits  phone_format
Data      (5): csv_to_array  array_to_key_value  json_decode  json_encode  implode
Date      (4): age  date_to_iso8601  date_to_timestamp  relative_date
Encoding  (3): base64_encode  base64_decode  hash
Numeric   (4): currency_format  percentage  ordinal  number_to_words
String    (7): camel_case  snake_case  kebab_case  pascal_case  mask  reverse  repeat
Structure (5): flatten  unflatten  pluck  group_by  rename_keys

Quick API

use KaririCode\Transformer\Provider\TransformerServiceProvider;

$engine = (new TransformerServiceProvider())->createEngine();
$result = $engine->transform(
    ['name' => 'hello world', 'cpf' => '123.456.789-09'],
    ['name' => ['camel_case'], 'cpf' => ['cpf_to_digits']]
);

$result->get('name');                  // "helloWorld"
$result->wasTransformed();             // true
$result->transformedFields();          // ['name', 'cpf']
$result->isFieldTransformed('name');   // true
$result->transformationCount();        // 2
cd transformer-example && composer install && php examples/06-all-rules.php

🧹 Sanitizer Example

Cleaning and normalizing untrusted input β€” 33 built-in sanitization rules.

sanitizer-example/ Β· README

What it covers

# Example Highlights
01 user-registration.php #[Sanitize] DTO, trim/capitalize/email_filter/digits_only, normalized bio
02 blog-post.php strip_tags vs html_purify, slug generation, truncate
03 brazilian-documents.php CPF, CNPJ, CEP β€” digits_only β†’ format_* pipeline ordering
04 product-import.php to_float β†’ round β†’ clamp, negative/overflow clamping
05 engine-api.php Raw array Engine API, dot-notation nested fields, normalize_date
06 all-rules-coverage.php All 33 rules β€” smoke test with full parameter reference

All 33 rules at a glance

String  (8): trim  normalize_whitespace  normalize_line_endings  truncate
             replace  regex_replace  strip_non_printable  slug
Case    (3): capitalize  lower_case  upper_case
Html    (5): strip_tags  html_purify  html_encode  html_decode  url_encode
Type    (4): to_float  to_int  to_bool  to_string  to_array
Numeric (3): round  clamp  to_string
Date    (2): normalize_date  timestamp_to_date
Filter  (3): digits_only  alpha_only  alphanumeric_only  email_filter
Format  (3): format_cpf  format_cnpj  format_cep

Quick API

use KaririCode\Sanitizer\Provider\SanitizerServiceProvider;

// Array API β€” no DTO needed
$engine = (new SanitizerServiceProvider())->createEngine();
$result = $engine->sanitize(
    ['name' => '  walmir silva  ', 'price' => '-5'],
    [
        'name'  => ['trim', 'capitalize'],
        'price' => ['to_float', ['clamp', ['min' => 0.01, 'max' => 9999.99]]],
    ]
);
$result->getSanitizedData(); // ['name' => 'Walmir Silva', 'price' => 0.01]
cd sanitizer-example && composer install && php examples/06-all-rules-coverage.php

🌱 Dotenv Example

Type-safe environment configuration β€” loading, casting, validation, encryption, and cascading.

dotenv-example/ Β· README

What it covers

# Example Highlights
01 basic-loading.php Dotenv::load(), get(), variable interpolation, isLoaded()
02 type-casting.php Auto type detection: int, float, bool, null, JSON array
03 validation-dsl.php Fluent DSL: required, between, allowedValues, custom, collect-all errors
04 schema-validation.php Declarative .env.schema β€” no PHP validation code needed
05 encryption.php AES-256-GCM: KeyPair::generate(), Encryptor, transparent decrypt on load
06 processors.php addProcessor(): Trim, Base64, CSV, UrlNormalizer, custom by glob
07 boot-env.php Cascade .env β†’ .env.local β†’ .env.{env} β†’ .env.{env}.local, debug()
08 env-helper.php env() global helper β€” typed, default-safe, Laravel-compatible

Quick API

use KaririCode\Dotenv\Dotenv;
use KaririCode\Dotenv\Enum\LoadMode;
use KaririCode\Dotenv\ValueObject\DotenvConfiguration;
use function KaririCode\Dotenv\env;

$dotenv = new Dotenv(__DIR__, new DotenvConfiguration(
    loadMode: LoadMode::Overwrite,
    typeCasting: true,
));
$dotenv->load();

env('DB_PORT');           // 5432 (int, auto-cast)
env('APP_DEBUG');         // false (bool)
env('MISSING', 'default'); // 'default' β€” never throws
cd dotenv-example && composer install && php run-all.php

πŸ” ClassDiscovery Example

Automatic class discovery β€” token-based and reflection scanners, multi-tier caching, attribute filters.

classdiscovery-example/ Β· README

What it covers

# Example Highlights
01 basic-file-scanner.php FileScanner, ComposerNamespaceResolver, DiscoveryResult, scan timing
02 attribute-filter-route.php AttributeFilter β€” find only #[Route]-annotated classes
03 service-auto-registration.php DI container auto-registration via #[Service]
04 event-listener-discovery.php Event dispatcher map from #[EventListener]
05 file-cache-strategy.php FileCacheStrategy β€” cold vs warm performance comparison
06 reflection-scanner.php ReflectionScanner β€” full attribute instances, methods, properties
07 attribute-scanner.php AttributeScanner::scanForAttribute() β€” 10Γ— faster, no class loading
08 composite-filter.php CompositeFilter::and() / ::or(), NamespaceFilter, StructuralFilter
09 chain-cache-strategy.php ChainCacheStrategy β€” Memory (L1) + File (L2) tiered cache
10 directory-scanner.php DirectoryScanner β€” depth limit, glob pattern, symlink policy
11 dependency-analyzer.php DependencyAnalyzer, Tarjan circular dependency detection
12 result-methods.php filter(), merge(), hasErrors(), hasClass(), getClass()
13 psr11-integration.php PSR11Integration, ConfiguratorBridge β€” framework integration factories

Quick API

use KaririCode\ClassDiscovery\Filter\AttributeFilter;
use KaririCode\ClassDiscovery\Scanner\{ComposerNamespaceResolver, FileScanner};

$scanner = new FileScanner(new ComposerNamespaceResolver(
    composerJsonPath: __DIR__ . '/composer.json',
    includeDevAutoload: false,
));
$scanner->addFilter(new AttributeFilter(Route::class));

$result = $scanner->scan(['src/Controller']);

foreach ($result as $fqcn => $meta) {
    // $meta->filePath, $meta->attributes[], $meta->isFinal, ...
}

echo $result->count() . " controllers in "
   . round($result->getScanDuration() * 1000, 1) . "ms\n";
cd classdiscovery-example && composer install && php run-all.php

Running Everything

Individual projects

# Transformer
cd transformer-example && composer install
php examples/06-all-rules.php           # all 32 rules

# Sanitizer
cd sanitizer-example && composer install
php examples/06-all-rules-coverage.php  # all 33 rules

# Dotenv
cd dotenv-example && composer install
php run-all.php                          # all 8 examples

# ClassDiscovery
cd classdiscovery-example && composer install
php run-all.php                          # all 13 examples

All at once

for dir in transformer-example sanitizer-example dotenv-example classdiscovery-example; do
    echo "=== $dir ===" && cd "$dir" && composer install -q && php run-all.php && cd ..
done

Library Versions

Library Version Examples Rules / Features
kariricode/transformer v2.0.0 6 32 rules
kariricode/sanitizer v2.x 6 33 rules
kariricode/dotenv v4.x 8 Full feature set
kariricode/class-discovery v2.x 13 All scanners & filters

Part of the KaririCode Framework ecosystem.

GitHub Organization Β· Packagist Β· Community Β· Docs

Built with ❀️ by Walmir Silva · KaririCode Framework

About

Collection of practical examples demonstrating how to use KaririCode libraries, APIs, and development tools.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages