PHPackages                             devhelp/piwik-silex-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. devhelp/piwik-silex-provider

ActiveLibrary[API Development](/categories/api)

devhelp/piwik-silex-provider
============================

integration of devhelp/piwik-api into Silex. Allows to create services for piwik api methods

0.1(10y ago)1211MITPHPPHP &gt;=5.3

Since Dec 15Pushed 9y ago4 watchersCompare

[ Source](https://github.com/devhelp/piwik-silex-provider)[ Packagist](https://packagist.org/packages/devhelp/piwik-silex-provider)[ Docs](http://devhelp.pl)[ RSS](/packages/devhelp-piwik-silex-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/3db88cc2969d221f1d25b5226910b9f3c22175c868d1733f9c9df443a59dcb37/68747470733a2f2f7472617669732d63692e6f72672f64657668656c702f706977696b2d73696c65782d70726f76696465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/devhelp/piwik-silex-provider)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4d6061f166dbb651ea8b841b3885460779da5af2463325780e5d69e4401e7a15/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64657668656c702f706977696b2d73696c65782d70726f76696465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/devhelp/piwik-silex-provider?branch=master)

Installation
------------

[](#installation)

For more information please check [composer website](http://getcomposer.org).

```
$ composer require 'devhelp/piwik-silex-provider:dev-master'

```

Sandbox
-------

[](#sandbox)

Working example can be found at [devhelp/piwik-silex-provider-sandbox](http://github.com/devhelp/piwik-silex-provider-sandbox)

Purpose
-------

[](#purpose)

Provides integration of [Piwik API](http://developer.piwik.org/api-reference/reporting-api) into [Silex](http://silex.sensiolabs.org). Adds services to the dependency injection container that allows to use Piwik API methods as services. It uses [devhelp/piwik-api](http://github.com/devhelp/piwik-api) library - check its documentation for more advanced usage.

Usage
-----

[](#usage)

### Register the provider

[](#register-the-provider)

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

$app->register(new Devhelp\Silex\Piwik\PiwikApiServiceProvider(array(
    'client' => 'my_piwik.client',
    'api' => array(
        'reader' => array(
            'url' => 'http://my_piwik_instance.piwik.pro',
            'default_params' => array(
                'token_auth' => 'piwik_token_auth',
                'idSite' => 123
            )
        )
    )
)));
```

### Create piwik client service that was set as 'client'

[](#create-piwik-client-service-that-was-set-as-client)

This example uses `PiwikGuzzleClient` class that is responsible for making http request to [Piwik](http://piwik.org). You can include this extension by including [devhelp/piwik-api-guzzle](http://github.com/devhelp/piwik-api-guzzle) in your project

```
//'guzzle' service must implement GuzzleHttp\ClientInterface
$app['my_piwik.client'] = $app->share(function () use ($app) {
    return new Devhelp\Piwik\Api\Guzzle\Client\PiwikGuzzleClient($app['guzzle']));
});
```

### Use API method in your use case

[](#use-api-method-in-your-use-case)

add service to the container

```
$app['my_service'] = $app->share(function () use ($app) {
    return new Acme\DemoBundle\Service\MyService($app['devhelp_piwik.api']);
});
```

example service definition

```
namespace Acme\DemoBundle\Service;

use Devhelp\Piwik\Api\Api;

class MyService
{

    /**
     * @var Api
     */
    private $piwikApi;

    public function __construct(Api $piwikApi)
    {
        $this->piwikApi = $piwikApi;
    }

    public function doSomething()
    {
        //...
        $this->piwikApi->getMethod('PiwikPlugin.pluginAction')->call();
        //...
    }
}
```

### Define API parameters resolved at runtime

[](#define-api-parameters-resolved-at-runtime)

You are allowed to set services as a params. If you do that then the service will be used to resolve the parameter at runtime. For example have a service that would return `token_auth` of logged in user

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

$app->register(new Devhelp\Silex\Piwik\PiwikApiServiceProvider(array(
    'client' => 'my_piwik.client',
    'api' => array(
        'reader' => array(
            'url' => 'http://my_piwik_instance.piwik.pro',
            'default_params' => array(
                'token_auth' => 'my_token_auth_provider',
                'idSite' => 123
            )
        )
    )
)));
```

`my_token_auth_provider` service definition (assumes that SecurityServiceProvider is registered)

```
$app['my_token_auth_provider'] = $app->share(function () use ($app) {
    return new Acme\DemoBundle\Param\MyTokenAuthProvider($app['security.token_storage']);
});
```

`MyTokenAuthProvider` class definition (assumes that User class has getPiwikToken method)

```
namespace Acme\DemoBundle\Param;

use Devhelp\Piwik\Api\Param\Param;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

class MyTokenAuthProvider implements Param
{

    /**
     * @var TokenStorageInterface
     */
    private $tokenStorage;

    public function __construct(TokenStorageInterface $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    public function value()
    {
        $token = $this->tokenStorage->getToken();

        return $token instanceof TokenInterface ? $token->getUser()->getPiwikToken() : null;
    }
}
```

### Define API methods as services

[](#define-api-methods-as-services)

```
$app['my_piwik_method'] = $app->share(function () use ($app) {
    return $app['devhelp_piwik.api']->getMethod('VisitFrequency.get');
});
```

Feedback/Requests
-----------------

[](#feedbackrequests)

Feel free to create an issue if you think that something is missing or needs fixing. Feedback is more than welcome!

Credits
-------

[](#credits)

Brought to you by : [devhelp.pl](http://devhelp.pl)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3852d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1479355?v=4)[devhelp](/maintainers/devhelp)[@devhelp](https://github.com/devhelp)

---

Top Contributors

[![pawelbaranski](https://avatars.githubusercontent.com/u/219097?v=4)](https://github.com/pawelbaranski "pawelbaranski (6 commits)")

---

Tags

matomopiwikpiwik

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/devhelp-piwik-silex-provider/health.svg)

```
[![Health](https://phpackages.com/badges/devhelp-piwik-silex-provider/health.svg)](https://phpackages.com/packages/devhelp-piwik-silex-provider)
```

###  Alternatives

[matomo/matomo-php-tracker

PHP Client for Matomo Analytics Tracking API

2213.7M36](/packages/matomo-matomo-php-tracker)[tobiassjosten/facebook-service-provider

Silex ServiceProvider for the Facebook SDK

266.1k](/packages/tobiassjosten-facebook-service-provider)[glen/slack-unfurl

Extensible Slack App for link unfurling

211.5k5](/packages/glen-slack-unfurl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
