Download the PHP package aptoma/silex-extras without Composer
On this page you can find all versions of the php package aptoma/silex-extras. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aptoma/silex-extras
More information about aptoma/silex-extras
Files in aptoma/silex-extras
Package silex-extras
Short Description Collection of common stuff for Silex powered applications
License MIT
Homepage https://github.com/aptoma/silex-extras
Informations about the package silex-extras
Silex Extras
Package consisting of reusable stuff for Silex powered applications.
It is collection of various services that will ease bootsrapping new Silex applications, keep best practices in sync across projects, and ensure we do stuff in a similar manner whenever we do something.
What's In It?
- Log processor for adding extra context to logs
- ServiceProvider for rich logging in Logstash format
- Base Application class for doing common stuff we always do in Silex applications
- Error handler that outputs stuff as json if
Accept: application/json
- TestToolkit to bootstrap functional testing of Silex applications
- API key user authentication
- Storage interface, with local file and Level3 implementations
- Ftp upload abstraction, basically a wrapper around native FTP functionality
- Level3 upload service, for uploading stuff to Level3
- ConsoleLoggerServiceProvider, for integrating the logger with the console
- CacheServiceProvider, for Memcached and Redis implementations of Doctrin Cache (can also be used standalone)
- GuzzleServiceProvider for extra Guzzle features
- Guzzle HttpCallInterceptorPlugin for testing with Guzzle services
Aptoma\Ftp
Wraps native PHP FTP functions in an object oriented manner. It's designed for working with Level3 CDN, and thus has a concept of multiple paths for upload.
Usage:
``
The class has a few more features for validating upload integrity and moving the file to publish location after upload. Read the source :)
Aptoma\Service\Level3Service
Provides an abstraction for uploading files to Level3. You need to provide a
an Ftp
instance and various paths, and can then simply do:
$service->upload($fileContents, $targetFileName, $relativeLocalTempDir);
.
After upload, the file will be renamed and put in a folder matching it's checksum, in order to avoid duplicate uploads, and to deal with Level3's (sensible) limitation of max number of files in a directory. The full public url is returned. Strictly speaking, this isn't actually Level3 specific, but more a two-step strategy for validated uploads.
There's also a bundled Level3ServiceProvider for simpler integration with Silex.
Aptoma\Log
This folder provides two classes:
ExtraContextProcessor
for always adding a predefined set of extra fields to log entriesRequestProcessor
for adding client ip, unique request token and username to all entriesMonologGuzzleLogAdapater
for integrating Monolog with Guzzle, to log request times and errors
Usage is simple:
``
Aptoma\Silex\Provider\ExtendedLoggerServiceProvider
This is a service provider that automatically adds the above mentioned RequestProcessor
,
as well as a LogstashFormatter if you have specified monolog.logstashfile
.
The LogstashFormatter can also add some extra context to each record:
``
These extra fields will help us classify records in our consolidated logging infrastructure (Loggly, Logstash and friends), and lead to great success.
Aptoma\Silex\Provider\ConsoleLoggerServiceProvider
This service provider makes it easy to show log messages from services in the console,
without having to inject an instance of OutputInterface
into the services. This
requires version ~2.4 of Symfony Components. More info about the change is at the
Symfony Blog.
In your console application, you can now do something like this:
``
You will still use the normal OutputInterface
instance for command feedback
in your commands, but you will now also get output from anything your services
are logging.
The console logger overrides the default monolog.handler
in order to allow setting
a custom log file. If defined, it will use monolog.console_logfile
, and if not, it
will fall back to monolog.logfile
.
This Provider is also available as standalone package: https://github.com/glensc/ConsoleLoggerServiceProvider
Aptoma\Silex\Application
This is a base application you can extend. It will add a json formatter for errors,
register ServiceControllerServiceProvider
and UrlGeneratorServiceProvider
,
automatically log execution time for scripts (up until the response has been sent),
and also exposes registerTwig
and registerLogger
, which you can use to set up
those with one line of code.
This class should include functionality that we always use, meaning it's not a collection of "nice to haves".
Aptoma\JsonErrorHandler
This class simply formats exceptions as JsonResponse
s, provided the client
has sent an Accept: application/json
header. It will be loaded automatically
by the base Application
class mentioned above, or it can be registered manually:
``
Aptoma\TestToolkit
This includes a BaseWebTestCase you can use to bootstrap your test, and an
associated TestClient
with shortcuts for postJson($url, $data)
and
putJson($url, $data)
.
To use it, you need to have your tests extend it, and probably also add the path to your bootstrap file:
``
Aptoma\Security
Component for API key user authentication.
All it requires is a UserProvider and an encoder to encode the API key. It'll typically be used in your app like this:
``
It can then be attached to any firewall of your choice:
``
CacheServiceProvider
Registers services for cache.memcached
and cache.predis
, as well as a generic
cache
, which can be configured to return either of these (Memcached by default).
``
See below for config options for Memcached.
MemcachedServiceProvider
Registers Memcached as a service, and takes care of prefixes and persistent connections. It returns an instance of \Memcached.
``
PredisServiceProvider
Registers Predis as a service. It returns an instance of \Predis\Client.
``
GuzzleServiceProvider
Extends the base GuzzleServiceProvider to allow registering global plugins, and also adds a few plugins:
- generic logging of each request
- logging of total requests
- adding of request token header to outgoing requests
- cache plugin for HTTP based caching
To configure which cache storage to use, define $app['guzzle.default_cache']
,
which should be a string referencing the cache service to use, ie. 'cache.memcached'.
``
Guzzle HttpCallInterceptorPlugin
Guzzle plugin for use in unit testing to ensure there are no calls made to any external services. In your test setup, do something like this:
``
All versions of silex-extras with dependencies
silex/silex Version ~1.0
symfony/http-foundation Version ~2.4
symfony/browser-kit Version ~2.2
symfony/css-selector Version ~2.2
symfony/monolog-bridge Version ~2.2
symfony/security Version ~2.3
symfony/finder Version ~2.2
symfony/filesystem Version ~2.2