Search by

modernman00 / shared-lib

modernman00

Shared library for common functions and classes across projects

Package info

github.com/modernman00/shared-lib

pkg:composer/modernman00/shared-lib

Statistics

Installs: 251

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 12

v2.11.0 2026-10-29 20:27 UTC

This package is auto-updated.

Last update: 2026-10-29 20:28:23 UTC


README

CI/CD Pipeline PHP Version License Latest Version

A comprehensive PHP shared library containing common functions and classes for use across multiple projects.

Features

  • Authentication & Security: JWT handling, secure sessions, token management
  • Database Operations: PDO utilities, query builders, database helpers
  • Form Building: Bootstrap and Bulma form builders
  • File Management: Upload handling, image optimization, virus scanning
  • Email Services: PHPMailer integration, email templates
  • Validation & Sanitization: Input validation, data sanitization
  • Rate Limiting: Request throttling and rate limiting
  • Logging: Monolog integration for structured logging
  • Exception Handling: Custom exception classes

Installation

Install via Composer:

composer require waleolaogun/shared-lib

Requirements

  • PHP 8.1 or higher
  • Composer for dependency management

Usage

Basic Example

<?php

require_once 'vendor/autoload.php';

use Src\Auth;
use Src\Db;
use Src\Utility;

// Initialize database connection
$db = new Db();

// Use authentication
$auth = new Auth($db);

// Use utility functions
$sanitized = Utility::sanitizeInput($_POST['data']);

Available Classes

  • Src\Ai\VoiceTranscriptionService - Whisper audio transcription (£0 HF serverless)
  • Src\Ai\ContentModerationService - Photo NSFW safety & toxicity classification
  • Src\Ai\EmbeddingService - Vector embeddings & in-memory cosine ranking
  • Src\Ai\ResilientAiChat - Resilient multi-tier LLM fallback (DeepSeek -> OpenAI -> HF)
  • Src\Ai\AiImageGenerationService - Generative event poster & theme background studio (FLUX.1-schnell / SDXL)
  • Src\Ai\AiVisionService - Multimodal vision for receipt / bar bill splitting & fridge meal planning (Qwen2-VL)
  • Src\Ai\AiEntertainmentService - AI Best Man speechwriter, comedy roast master & dispute referee (Llama-3.2)
  • Src\Ai\ResilientWebSearchService - Grounded web search & safe Markdown fetch across all 8 portfolio apps (72h SHA-256 cache + DeepSeek Search/Fetch $0.75/1k + £0 Open-Web fallback)
  • Src\Ai\HuggingFaceInferenceGateway - Hardened HF API client with SSRF protection

AI Services Example (£0 Serverless Tier)

use Src\Ai\AiImageGenerationService;
use Src\Ai\AiVisionService;
use Src\Ai\AiEntertainmentService;

// 1. Generative Event Flyer Background Studio
$imageService = new AiImageGenerationService();
$flyerBg = $imageService->generatePosterBackground("Liam's 7th Birthday with T-Rex", 'kids_storybook_dino');
$dataUri = $flyerBg['data_uri']; // Passed to shared-js-lib AiFlyerStudio for crisp Canvas typography

// 2. Bar Tab & Receipt Multimodal Splitter
$visionService = new AiVisionService();
$parsedBill = $visionService->parseReceipt($_FILES['receipt']['tmp_name']);
// returns: ['items' => [['name' => 'Nachos', 'price' => 9.50, 'quantity' => 1]], 'total' => 40.20, ...]

// 3. AI Speechwriter & Roast Master
$entertainment = new AiEntertainmentService();
$speech = $entertainment->generateSpeech('Dave', '30th Birthday', ['Ibiza pool dive', 'Sourdough obsessed'], 'humorous_roast');
// returns: ['title' => '...', 'speech_text' => '...', 'suggested_toast' => '...', 'delivery_tips' => [...]]

// 4. Household Dispute Referee
$ruling = $entertainment->arbitrateDispute('Liam', 'I unloaded the dishwasher', 'Maya', 'He left all the pots', 'household_chores');
// returns: ['verdict' => '...', 'compromise_action_plan' => [...], 'penalty_or_chore' => '...', 'closing_quip' => '...']
use Src\Ai\VoiceTranscriptionService;
use Src\Ai\ContentModerationService;
use Src\Ai\EmbeddingService;
use Src\Ai\ResilientAiChat;

// 1. Voice Transcription (Whisper)
$transcriber = new VoiceTranscriptionService();
$result = $transcriber->transcribeFile($_FILES['audio']['tmp_name']);
$text = $result['text'];

// 2. Photo NSFW Moderation
$moderator = new ContentModerationService();
$safety = $moderator->checkPhotoSafety($_FILES['photo']['tmp_name']);
if ($safety['flagged']) {
    throw new \Exception('Image rejected: inappropriate content detected.');
}

// 3. Semantic Search Vector Embeddings & Cosine Ranking
$embedder = new EmbeddingService();
$queryVector = $embedder->generateEmbedding("affordable wedding venue in London");
$rankedEvents = $embedder->rankBySimilarity($queryVector, $allEventsWithVectors, 10);

// 4. Resilient AI Chat (Multi-Tier Outage Protection)
$chat = new ResilientAiChat();
$reply = $chat->chat([
    ['role' => 'system', 'content' => 'You are a helpful assistant.'],
    ['role' => 'user', 'content' => 'Suggest 3 party themes for a 10th birthday.']
]);
  • Src\Db - Database operations and utilities
  • Src\Email - Email sending capabilities
  • Src\FileUploader - File upload handling
  • Src\JwtHandler - JWT token management
  • Src\Limiter - Rate limiting functionality
  • Src\Utility - General utility functions
  • And many more...

Development

Setting Up Development Environment

  1. Clone the repository:

    git clone https://github.com/modernman00/shared-lib.git
    cd shared-lib
  2. Install dependencies:

    composer install
  3. Run code quality checks:

    # PHP CS Fixer
    vendor/bin/php-cs-fixer fix --dry-run --diff
    
    # PHPStan static analysis
    vendor/bin/phpstan analyse

Code Quality Standards

This project follows PSR-12 coding standards and uses:

  • PHP CS Fixer for code formatting
  • PHPStan for static analysis (Level 6)
  • Composer audit for security vulnerability scanning

CI/CD Pipeline

The project uses GitHub Actions for continuous integration and deployment:

  • Automated Testing: Runs on PHP 8.1, 8.2, and 8.3
  • Code Quality Checks: PHP CS Fixer and PHPStan analysis
  • Security Scanning: Dependency vulnerability checks
  • Automated Dependency Updates: Dependabot integration
  • Release Management: Automated release asset creation

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and ensure they pass all quality checks
  4. Commit your changes: git commit -m 'Add amazing feature'
  5. Push to the branch: git push origin feature/amazing-feature
  6. Open a Pull Request

All pull requests are automatically tested against our CI pipeline.

Running Tests Locally

# Install development dependencies
composer install --dev

# Run PHP CS Fixer
vendor/bin/php-cs-fixer fix --dry-run --diff --verbose

# Run static analysis
vendor/bin/phpstan analyse --memory-limit=1G

# Check for security vulnerabilities
composer audit

Versioning

This project uses Semantic Versioning. For available versions, see the releases page.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, please open an issue on the GitHub repository.

Changelog

For a detailed changelog, see RELEASES.