PHP code example of m1 / stash-silex

1. Go to this page and download the library: Download m1/stash-silex 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/ */

    

m1 / stash-silex example snippets


$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pools.options' => array(
        'fs' => array(
            'driver' => 'FileSystem',
            'options' => array(
                'path' => __DIR__.'/../../app/cache',
            ),
        ),
        'mc' => array(
            'driver' => 'Memcache',
            'options' => array(
                'servers' => array(
                    '127.0.0.1', '11211'
                )
            ),
        ),
    ),
));

// same thing
$item1 = $app['pools']['fs']->getItem('path/to/item');
$item1 = $app['pool']->getItem('path/to/item');

$item2 = $app['pools']['mc']->getItem('path/to/item');


$app['mylog'] = $app->share(function($app) {
    $logger = new \Monolog\Logger('mylog');
    $logger->pushHandler(new Monolog\Handler\StreamHandler('/logfile/mylog.log', Logger::INFO));
    return $logger;
});

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'logger' => 'mylog'
    )
));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'session' => true
    )
));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'session' => array(
            'prefix' => 'session_name',
            'expiretime' => 3200
        )
    )
));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        )
    )
));

// Without options
$app['session.storage.handler'] = $app->share(function ($app) {
    return new M1\StashSilex\StashSessionHandler($app['pool']);
});

// With options
$app['session.storage.handler'] = $app->share(function ($app) {
    return new M1\StashSilex\StashSessionHandler($app['pool'], array(
        'prefix' => 'session_name',
        'expiretime' => 3200
    ));
});

 php
$app->register(new M1\StashSilex\StashServiceProvider());
 php
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
    )
));

$item = $app['pool']->getItem('path/to/item');
 php
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
    )
));
 php

$app->register(new Silex\Provider\MonologServiceProvider(), array(
    'monolog.logfile' => __DIR__.'/../../app/logs/app/dev.log',
));

$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pool.options' => array(
        'driver' => 'FileSystem',
        'options' => array(
            'path' => __DIR__.'/../../app/cache',
        ),
        'logger' => 'monolog'
    )
));
 php

$app->register(new M1\Vars\Provider\Silex\VarsServiceProvider('example.yml'), array(
    'vars.options' => array(
        'variables' => array(
            'dir' => __DIR__
        ),
)));
    
$app->register(new M1\StashSilex\StashServiceProvider(), array(
    'pools.options' => $app['vars']['pools']
));