PHP code example of phossa2 / shared

1. Go to this page and download the library: Download phossa2/shared library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phossa2 / shared example snippets


  
  namespace Phossa2\Cache\Exception;

  use Phossa2\Shared\Exception\ExceptionInterface;

  class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
  {
  }
  

    
    namespace Phossa2\Cache\Message;

    use Phossa2\Shared\Message\Message;

    class CacheMessage extends Message
    {
        // 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',
        ];
    }
    

    use Phossa2\Cache\Message\CaseMessage;
    ...
    // throw exception
    throw new \RuntimeException(
        CacheMessage::get(CacheMessage::CACHE_DRIVER_FAIL, get_class($driver)),
        CacheMessage::CACHE_DRIVER_FAIL
    );
    

    namespace Phossa2\Cache;

    use Phossa2\Cache\Message\CaseMessage;
    use Phossa2\Shared\Message\Loader\LanguageLoader;

    // set language to 'zh_CN'
    $langLoader = new LanguageLoader('zh_CN');

    // will load `CacheMessage.zh_CN.php` in the same dir as `CacheMessage.php`
    CacheMessage::setLoader($langLoader);

    // print message in chinese
    echo CacheMessage::get(
        CacheMessage::CACHE_MESSAGE, get_class($object)
    );
    

    namespace Phossa2\Cache;

    use Phossa2\Cache\Message\CaseMessage;
    use Phossa2\Shared\Message\Formatter\HtmlFormatter;

    // format message as HTML
    $formatter = new HtmlFormatter();

    CacheMessage::setFormatter($formatter);

    // print as HTML
    echo CacheMessage::get(
        CacheMessage::CACHE_MESSAGE, get_class($object)
    );
    

    
    namespace Phossa2\MyPackage;

    class MyStaticClass extends \Phossa2\Shared\Base\StaticAbstract
    {
        ...
    }