PHP code example of aptoma / silex-extras

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

    

aptoma / silex-extras example snippets


$ftp = new Ftp($hostname, $username, $password, $logger);
$file = new File($pathToFile);

$destination = 'path/on/server/with/filename.txt';
// All directories needs to be created before upload
$ftp->preparePaths(array($destination));
$ftp->put($destination, $file->getRealPath());

use Monolog\Logger;
use Aptoma\Log\RequestProcessor;

$app = new \Silex\Application(...);

$app['logger']->pushProcessor(new RequestProcessor($app));
$app['logger']->pushProcessor(new ExtraContextProcessor(array('service' => 'my-service', 'environment' => 'staging')));

$app['meta.service'] = 'drvideo-metadata-admin-gui'; // The name of the service, consult with AMP
$app['meta.customer'] = 'Aptoma'; // The name of customer for this record
$app['meta.environment'] = 'production'; // The environment of the current installation

use Symfony\Component\Console\Application;

$app = ', '1.0');
// You should only register this service provider when running commands
$app->register(new \Aptoma\Silex\Provider\ConsoleLoggerServiceProvider());

$console->addCommands(
    array(
    //...
    )
);

$console->run($app['console.input'], $app['console.output']);

$jsonErrorHandler = new Aptoma\JsonErrorHandler($app);
$app->error(array($jsonErrorHandler, 'handle'));

class MyObjectTest extends TestToolkit\BaseWebTestCase
{
    public function setUp()
    {
        $this->pathToAppBootstrap = __DIR__.'/../../app/app.php';
        parent::setUp();
    }
}

$app->register(
    new Aptoma\Silex\Provider\ApiKeyServiceProvider(),
    array(
        'api_key.user_provider' => new App\Specific\UserProvider(),
        'api_key.encoder' => new App\Specific\Encoder()
    )
);

$app->register(
    new Silex\Provider\SecurityServiceProvider(),
    array(
        'security.firewalls' => array(
            // ...
            'secured' => array(
                'pattern' => '^.*$',
                'api_key' => true
                // more settings...
            )
        )
    )
);


$app->register(new Aptoma\Silex\Provider\MemcachedServicerProvider());
$app->register(new Aptoma\Silex\Provider\CacheServicerProvider());

$app['cache']->save('mykey', 'myvalue');



$app['memcached.identifier'] = 'my_app';
$app['memcached.prefix'] = 'ma_';
$app['memcached.servers'] = array(
        array('host' => '127.0.0.1', 'port' => 11211),
    );

$app->register(new Aptoma\Silex\Provider\MemcachedServicerProvider());

$app['memcached']->set('mykey', 'myvalue');



$app['redis.host'] = '127.0.0.1';
$app['redis.port'] = 6379;
$app['redis.prefix'] = 'prefix::';
$app['redis.database'] = 0;

$app->register(new Aptoma\Silex\Provider\PredisClientServicerProvider());

$app['predis.client']->set('mykey', 'myvalue');


$app->register(new GuzzleServiceProvider(), array('guzzle.services' => array()));
$app->finish(array($app['guzzle.request_logger_plugin'], 'writeLog'));

$app['guzzle.plugins'] = $app->share(
    function () use ($app) {
        return array(
            $app['guzzle.log_plugin'],
            $app['guzzle.request_logger_plugin'],
            $app['guzzle.request_token_plugin'],
            $app['guzzle.cache_plugin'],
        );
    }
);


$this->app['guzzle.plugins'] = $this->app->share(
    $this->app->extend(
        'guzzle.plugins',
        function (array $plugins, $app) {
            $plugins[] = new HttpCallInterceptorPlugin($app['logger']);

            return $plugins;
        }
    )
);

// Intercept errors and fail tests, if you don't do this, you'll most often get
// a rather cryptic error message
$this->app->error(
    function (HttpCallToBackendException $e) use ($testCase) {
        $testCase->fail($e->getMessage());
    },
    10
);

$this->app->error(
    function (BatchTransferException $e) use ($testCase) {
        $testCase->fail($e->getMessage());
    },
    10
);