2017 © Pedro Peláez
 

library universal

image

corneltek/universal

  • Saturday, March 31, 2018
  • by c9s
  • Repository
  • 3 Watchers
  • 14 Stars
  • 63,035 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

Universal

Universal is a general proprose PHP library., (*1)

Build Status, (*2)

Components

  • ClassLoaders
  • Container
  • HTTPRequest

Classloader

SplClassLoader

use Universal\ClassLoader\SplClassLoader;
$loader = new \UniversalClassLoader\SplClassLoader( array(  
        'Vendor\Onion' => 'path/to/Onion',
        'Vendor\CLIFramework' => 'path/to/CLIFramework',
));
$loader->addNamespace(array( 
    'NS' => 'path'
));
$loader->useIncludePath();
$loader->register();

BasePathClassLoader

$loader = new BasePathClassLoader( array( 
    'vendor/pear', 'external_vendor/src'
) );
$loader->useEnvPhpLib();
$loader->register();

Include Path Manipulator

Include Path manipulator, (*3)

$includer = new PathIncluder(array( 'to/path', ... ));
$includer->add( 'path/to/lib' );
$includer->setup();   // write set_include_path

Http

StreamResponse

MXHR support, (*4)

    $response = new Universal\Http\StreamResponse;
    for( $i = 0 ; $i < 30000 ; $i++ ) {
        $response->write(json_encode(array('i' => $i)), array(
            'Content-Type' => 'application/json',
        ));
        usleep(200000);
    }
    $response->finish();

HttpRequest

For multiple files:, (*5)

<?php

$req = new HttpRequest;
foreach( $req->files as $f ) {
    $extname = $f->getExtension();
    $filename = $f->getPathname();
}

$req->param( 'username' );   // get $_REQUEST['username'];

$req->get->username;    // get $_GET['username'];

$req->post->username;   // get $_POST['username'];

$req->server->path_info;  // get $_SERVER['path_info'];

To get FILE:, (*6)

$req = new HttpRequest;

Get $_FILES['uploaded'] hash:, (*7)

$req->files->uploaded;

Get file size:, (*8)

$req->files->uploaded->size;

Get file mime type:, (*9)

$req->files->uploaded->type; // plain/text

Get upload error:, (*10)

$req->files->uploaded->error;

Foreach file:, (*11)

foreach( $req->files->uploaded as $f ) {
    $f->size;
}

ObjectContainer

Construct a $container object or inherit from it:, (*12)

$container = new Universal\Container\ObjectContainer;

Register a object builder for lazy building., (*13)

$container->mailer = function() {
    return new YourMailer;
};

To get singleton object via __get magic method:, (*14)

$mailer = $container->mailer;

Or get singleton object from instance method:, (*15)

$mailer = $container->instance('mailer');

To build a new object:, (*16)

$mailer = $container->build('mailer');

To build a new object with arguments:, (*17)

$mailer = $container->build('mailer', array( ... ));

Session

Supported Session Storage backend:, (*18)

  • Memcache
  • Redis
  • Native

use ObjectContainer to pass options:, (*19)

$container = new Universal\Container\ObjectContainer;
$container->state = function() {
    return new Universal\Session\State\NativeState;
};
$container->storage = function() {
    return new Universal\Session\Storage\NativeStorage;
};

Native Session:, (*20)

$session = new Universal\Session\Session(array(  
    'state'   => new Universal\Session\State\NativeState,
    'storage' => new Universal\Session\Storage\NativeStorage,
));
$counter = $session->get( 'counter' );
$session->set( 'counter' , ++$counter );
echo $session->get( 'counter' );

Session with memcache backend:, (*21)

$session = new Universal\Session\Session(array(  
    'state'   => new Universal\Session\State\CookieState,
    'storage' => new Universal\Session\Storage\MemcacheStorage,
));
$counter = $session->get( 'counter' );
$session->set( 'counter' , ++$counter );
echo $session->get( 'counter' );

Event

use Universal\Event\PhpEvent;
$e = PhpEvent::getInstance();

// register your handler
$e->register( 'test', function($a,$b,$c) {
    // do what you want

});

// trigger event handlers
$e->trigger( 'test' , 1,2,3  );

Requirement Checker

try {
    $require = new Universal\Requirement\Requirement;
    $require->extensions( 'apc','mbstring' );
    $require->classes( 'ClassName' , 'ClassName2' );
    $require->functions( 'func1' , 'func2' , 'function3' )
}
catch( RequireExtensionException $e ) {

}
catch( RequireFunctionException $e ) {

}
catch( RequireClassException $e ) {

}

The Versions

31/03 2018

0.0.2

0.0.2.0

  Sources   Download

31/03 2018

1.2.3

1.2.3.0

  Sources   Download

01/06 2017

dev-master

9999999-dev http://github.com/corneltek/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

11/06 2016

1.8.0

1.8.0.0 http://github.com/corneltek/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

07/11 2015

1.7.2

1.7.2.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

07/10 2015

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

07/10 2015

1.7.1

1.7.1.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

31/08 2015

1.7.0

1.7.0.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

22/08 2015

1.6.0

1.6.0.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

17/07 2015

1.5.0

1.5.0.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

13/07 2015

1.4.0

1.4.0.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

07/07 2015

dev-develop

dev-develop http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

03/07 2015

1.3.4

1.3.4.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

23/03 2013

1.3.3

1.3.3.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

23/03 2013

1.3.2

1.3.2.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

21/03 2013

1.3.1

1.3.1.0 http://github.com/c9s/Universal

Universal library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires