2017 © Pedro Peláez
 

library phossa-shared

The shared package for other phossa packages

image

phossa/phossa-shared

The shared package for other phossa packages

  • Monday, May 23, 2016
  • by phossa
  • Repository
  • 1 Watchers
  • 0 Stars
  • 848 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

phossa-shared

Build Status HHVM Latest Stable Version License, (*1)

Introduction

Phossa-shared is the shared package required by other phossa packages., (*2)

Installation

Install via the composer utility., (*3)

composer require "phossa/phossa-shared=1.*"

or add the following lines to your composer.json, (*4)

{
    "require": {
       "phossa/phossa-shared": "^1.0.9"
    }
}

Features

  • Exception, (*5)

    All phossa exceptions implement Phossa\Shared\Exception\ExceptionInterface. To extend phossa exceptions,, (*6)

    <?php
    namespace Phossa\Cache\Exception;
    
    class BadMethodCallException extends
      \Phossa\Shared\Exception\BadMethodCallException
    {
    }
    
    
  • Message, (*7)

    MessageAbstract class is the base class for all Message classes in all phossa packages., (*8)

    • Define package related Message class

    Message class is used to convert message code into human-readable messages, and MUST define its own property $messages., (*9)

    <?php
    namespace Phossa\Cache\Message;
    
    use Phossa\Shared\Message\MessageAbstract;
    
    class Message extends MessageAbstract
    {
        // use current year_month_date_hour_minute
        const CACHE_MESSAGE     = 1512220901;
    
        // driver failed
        const CACHE_DRIVER_FAIL = 1512220902;
    
        protected static $messages = [
            self::CACHE_MESSAGE      => 'cache %s',
            self::CACHE_DRIVER_FAILT => 'cache driver %s failed',
        ];
    }
    
    • Message class usage

    Usually only Message::get() and Message::CONST_VALUE are used., (*10)

    use Phossa\Cache\Message\Message;
    ...
    // throw exception
    throw new Exception\RuntimeException(
        Message::get(Message::CACHE_DRIVER_FAIL, get_class($driver)),
        Message::CACHE_DRIVER_FAIL
    );
    
    • Message loader

    Used for loading different code to message mapping such as language files., (*11)

    namespace Phossa\Cache;
    
    use Phossa\Shared\Message\Loader\LanguageLoader;
    
    // set language to 'zh_CN'
    $langLoader = new LanguageLoader('zh_CN');
    
    // will load local `Message\Message.zh_CN.php` language file
    Message\Message::setLoader($langLoader);
    
    // print message in chinese
    echo Message\Message::get(
        Message::CACHE_MESSAGE, get_class($object)
    );
    
    • Message formatter

    Used for formatting messages for different devices such as HTML page., (*12)

    namespace Phossa\Cache;
    
    use Phossa\Shared\Message\Formatter\HtmlFormatter;
    
    // format message as HTML
    $formatter = new HtmlFormatter();
    
    Message\Message::setFormatter($formatter);
    
    // print as HTML
    echo Message\Message::get(
        Message::CACHE_MESSAGE, get_class($object)
    );
    
  • Pattern, (*13)

    Commonly used patterns in Interface or Trait, (*14)

    • StaticTrait

    Used to be included in a static class which can not extends StaticAbstract, (*15)

    <?php
    namespace Phossa\MyPackage;
    
    class MyStaticClass extends SomeClass
    {
        use \Phossa\Shared\Pattern\StaticTrait;
        ...
    }
    
    • StaticAbstract

    Used to be extended by other classes., (*16)

    <?php
    namespace Phossa\MyPackage;
    
    class MyStaticClass extends \Phossa\Shared\Pattern\StaticAbstract
    {
        ...
    }
    
    • SingletonInterface and SingletonTrait

    Used to be included in a singleton class., (*17)

    <?php
    namespace Phossa\MyPackage;
    
    class MySingletonClass extends SomeClass
    {
        use \Phossa\Shared\Pattern\SingletonTrait;
        ...
    }
    

    Usage,, (*18)

    $obj =  MySingletonClass::getInstance();
    

    This singleton implementation has a feature which allows singleton class to extended., (*19)

    <?php
    namespace Phossa\MyPackage;
    
    class MyNewSingletonClass extends MySingletonClass
    {
        ...
    }
    
    • ShareableInterface and ShareableTrait

    Multiple instances are allowed for Shareable, but only one global copy. Such as global event manager and lots of local event managers., (*20)

    <?php
    namespace Phossa\Event;
    
    use Phossa\Shared\Pattern\ShareableInterface;
    
    class EventManager implements ShareableInterface
    {
        use \Phossa\Shared\Pattern\ShareableTrait;
        ...
    }
    

    Usage,, (*21)

    // global event manager instance
    $globalEM = EventManager::getShareable();
    
    // local event manager
    $localEM  = new EventManager();
    
    // this EM global ?
    if ($globalEM->isShareable()) {
        ...
    } else {
        ...
    }
    
  • Taggable, (*22)

    Added TaggableInterface and TaggableTrait., (*23)

  • Support PHP 5.4+, PHP 7.0+, HHVM, (*24)

  • PHP7 ready for return type declarations and argument type declarations., (*25)

  • PSR-1, PSR-2, PSR-4 compliant., (*26)

  • Decoupled packages can be used seperately without the framework., (*27)

Dependencies

PHP >= 5.4.0, (*28)

License

MIT License, (*29)

The Versions

23/05 2016

dev-master

9999999-dev https://github.com/phossa/phossa-shared

The shared package for other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

23/05 2016

1.0.11

1.0.11.0 https://github.com/phossa/phossa-shared

The shared package for other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

11/04 2016

1.0.10

1.0.10.0 https://github.com/phossa/phossa-shared

The shared package for other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

31/03 2016

1.0.9

1.0.9.0 https://github.com/phossa/phossa-shared

The shared package for other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

29/02 2016

1.0.8

1.0.8.0 https://github.com/phossa/phossa-shared

The shared package for other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

02/02 2016

1.0.7

1.0.7.0 https://github.com/phossa/phossa-shared

The shared package for all other phossa packages

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

29/01 2016

1.0.6

1.0.6.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

29/01 2016

1.0.5

1.0.5.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

28/01 2016

1.0.4

1.0.4.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

25/01 2016

1.0.3

1.0.3.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

21/01 2016

1.0.2

1.0.2.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa

02/11 2015

1.0.0

1.0.0.0 https://github.com/phossa/phossa-shared

The shared package of Phossa framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework phossa