GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - SerafimArts/Stream: PHP realtime source streaming library

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
resources
resources
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.scrutinizer.yml
.scrutinizer.yml
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

Stream

Travis CI Coverage Scrutinizer CI Latest Stable Version Latest Unstable Version License MIT Total Downloads

Sources Streaming Package

Installation

composer require serafim/stream

Package on packagist.org

Introduction

Stream package provides the ability to override the data contained within the files in real time.

Protocol Streaming

<?php

use Serafim\Stream\Stream;

Stream::create('some')
    ->tryRead(function (string $pathname): string {
        return $pathname;
    });

echo \file_get_contents('some://example'); // string(7) "example"
<?php

use Serafim\Stream\Stream;

Stream::create('four')
    ->onRead(function (string $sources): string {
        return $sources . "\n" . 'return 4;';
    });

echo require 'four://example.php'; // int(1) "4"

Composer

<?php
use Serafim\Stream\ClassLoader;

$composer = require __DIR__ . '/vendor/autoload.php';

$loader = new ClassLoader($composer);
$loader->when
    // The stream will be triggered only on those files
    // whose namespace starts with "App"
    ->namespace('App')
    ->then(function (string $sources): string {
        \var_dump(42);
        
        return $sources;
    });

// When loading this class, var_dump(42) will be displayed.
new App\Example();

Composer Filters

Each filter starts with calling the $loader->when method.

Filter where

It works when the result of an anonymous function passed to the method where returns the true.

$loader->when->where(function (string $class, string $pathname): bool {
    return $class === 'User';
});

$user = new User();

Filter not

It works when the result of an anonymous function passed to the method not returns the false.

$loader->when->not(function (string $class, string $pathname): bool {
    return $class !== 'User';
});

$user = new User();

Filter every

Works when each rule applied inside an anonymous function returns a positive result.

use Serafim\Stream\Filter\Conjunction;

$loader->when->every(function (Conjunction $fn) {
    $fn->where(...);
    // AND
    $fn->where(...);
});

Filter any

Works when any (one of) rule applied inside an anonymous function returns a positive result.

use Serafim\Stream\Filter\Disjunction;

$loader->when->any(function (Disjunction $fn) {
    $fn->where(...); 
    // OR
    $fn->where(...);
});

Filter fqn

Works in the case when the fqn (Fully qualified name) corresponds to the specified.

$loader->when->fqn('App\\User');

new App\User(); // Stream works
new Some\App\User(); // Stream does not work

Filter className

Works in the case when the class name corresponds to the specified.

$loader->when->className('User');

new App\User(); // OK
new Any\User(); // OK

Filter namespace

Works in the case when the namespace corresponds to the specified.

$loader->when->className('App');

new App\User(); // OK
new App\Message(); // OK

Filter fileName

Works in the case when the file name corresponds to the specified.

$loader->when->fileName('App');

new App(); // The stream is triggered if the file name matches the class name.

Filter pathNameMatches

The stream is triggered if the path matches the regular expression.

$loader->when->pathNameMatches('Models/.*');

Filter fileNameMatches

The stream is triggered if the file name matches the regular expression.

$loader->when->fileNameMatches('\w+Interface');

Filter classNameMatches

The stream is triggered if the class name matches the regular expression.

$loader->when->classNameMatches('\w+Interface');

Filter fqnMatches

The stream is triggered if the fqn (Fully qualified name) matches the regular expression.

$loader->when->fqnMatches('App\\.*?\\\w+Interface');

Filter withVendors

The stream is triggered if the file is loaded from the vendor directory (by default, all vendor files are ignored)

$loader->when->withVendors();

About

PHP realtime source streaming library

Topics

hookspatchingrealtimerestreamsourcesstreamingtranspilingwrapper

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

8 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.