PHPackages                             gremo/subscription-bundle - 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. [Payment Processing](/categories/payments)
4. /
5. gremo/subscription-bundle

AbandonedArchivedSymfony-bundle[Payment Processing](/categories/payments)

gremo/subscription-bundle
=========================

Symfony2 Bundle for managing subscriptions.

v1.0.0(13y ago)5331MITPHPPHP &gt;=5.3.2

Since Dec 14Pushed 13y ago1 watchersCompare

[ Source](https://github.com/gremo/GremoSubscriptionBundle)[ Packagist](https://packagist.org/packages/gremo/subscription-bundle)[ RSS](/packages/gremo-subscription-bundle/feed)WikiDiscussions master Synced today

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

GremoSubscriptionBundle [![Build Status](https://camo.githubusercontent.com/86ea4d62e7987814f18c330369e461d5751089b2475c6104ddd7c055a9aa61e8/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6772656d6f2f4772656d6f537562736372697074696f6e42756e646c652e706e67)](http://travis-ci.org/gremo/GremoSubscriptionBundle)
===============================================================================================================================================================================================================================================================================================================================

[](#gremosubscriptionbundle-)

Symfony2 Bundle for managing subscriptions.

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

[](#installation)

Add the following to your `deps` file (for Symfony 2.0.\*):

```
[GremoSubscriptionBundle]
    git=https://github.com/gremo/GremoSubscriptionBundle.git
    target=bundles/Gremo/SubscriptionBundle

```

Then register the namespaces with the autoloader (`app/autoload.php`):

```
$loader->registerNamespaces(array(
    // ...
    'Gremo' => __DIR__.'/../vendor/bundles',
    // ...
));
```

Or, if you are using Composer and Symfony 2.1.\*, add to `composer.json` file:

```
{
    "require": {
        "gremo/subscription-bundle": "*"
    }
}
```

Finally register the bundle with your kernel in `app/appKernel.php`:

```
public function registerBundles()
{
    $bundles = array(
        // ...
        new Gremo\SubscriptionBundle\GremoSubscriptionBundle(),
        // ...
    );

    // ...
}
```

Configuration
-------------

[](#configuration)

Bundle configuration is simple: you first need to specify an interval for the subscription periods. Use the format of `\DateInterval` [interval specification](http://php.net/manual/en/dateinterval.construct.php). For example, `P30D`, that is 30 days. Interval should be, at least, one day long.

Then implement `Gremo\SubscriptionBundle\Provider\ActivationDateProviderInterface`, in order to provide an activation date. Make this class a service and set its name as the `activation_provider` in the configuration:

```
gremo_subscription:
    interval: P30D
    activation_provider: my_activation_provider

```

### Activation date provider example

[](#activation-date-provider-example)

An example activation date provider, where activation date is the current logged user creation date:

```
use Gremo\SubscriptionBundle\Provider\ActivationDateProviderInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Security\Core\SecurityContext;

/**
 * @DI\Service("my_activation_provider")
 */
class MyActivationProvider implements ActivationDateProviderInterface
{
    /**
     * @var \Symfony\Component\Security\Core\SecurityContext
     */
    private $context;

    /**
     * @DI\InjectParams({"context" = @DI\Inject("security.context")})
     */
    public function __construct(SecurityContext $context)
    {
        $this->context = $context;
    }

    /**
     * @return \DateTime
     */
    public function getActivationDate()
    {
        $user = $this->context->getToken()->getUser();

        return $user->getCreatedAt();
    }
}
```

Usage
-----

[](#usage)

You can access the subscription service using the service container, for example in your controller code:

```
$subscription = $this->get('gremo_subscription'):
```

Say that today is 2012-12-12, interval is 30 days and activation date is 2012-09-01. Periods will be:

- From 2012-09-01 to 2012-09-30 inclusive, the first period
- From 2012-10-01 to 2012-10-30 inclusive
- From 2012-10-31 to 2012-11-29 inclusive
- From 2012-11-30 to 2012-12-29 inclusive, that is the current period

Access the current period from subscription:

```
$currentPeriod = $subscription->getCurrentPeriod(); // Period from 2012-11-30 to 2012-12-29

$firstDate = $currentPeriod->getFirstDate(); // DateTime object (2012-11-30)
$lastDate  = $currentPeriod->getLastDate();  // DateTime object (2012-12-29)
```

Class `BaseSubscription` implements `Countable`, `ArrayAccess`, `Iterator` PHP interfaces, so you can easly count, access and loop over each period. `BaseSubscriptionPeriod` inherits from PHP `DatePeriod` object, allowing to loop over each day of the period:

```
// Get periods count
$numPeriods = count($subscription); // 4

// Get the previous period
$previusPeriod = $subscription[$numPeriods - 1]; // Period from 2012-10-31 to 2012-11-29

// Loop over each day of the previous period
foreach($previusPeriod as date)
{
    // ...
}

// Loop over each period
foreach($subscription as $period)
{
    // ...
}

// Find out a period for the given date (may return null)
$period = $subscription->getPeriod(new \DateTime('2012-11-25')); // Period form 2012-10-01 to 2012-10-30
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

4948d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9a79689fe41827b4fd386dd42a9117115e27a4f946935d6ce77d7f6a76260fe?d=identicon)[gremo](/maintainers/gremo)

---

Top Contributors

[![gremo](https://avatars.githubusercontent.com/u/1532616?v=4)](https://github.com/gremo "gremo (2 commits)")

---

Tags

subscriptionrecurrences

### Embed Badge

![Health badge](/badges/gremo-subscription-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/gremo-subscription-bundle/health.svg)](https://phpackages.com/packages/gremo-subscription-bundle)
```

PHPackages © 2026

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