Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hellopablo committed May 10, 2021
1 parent bc5ae02 commit 8976b50
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/CONTRIBUTING.md
@@ -0,0 +1,3 @@
# How to Contribute

We'd love for you to help out. Read the contribution guidelines [here](http://docs.nailsapp.co.uk/contribute).
13 changes: 13 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,13 @@
version: 2
updates:

# Maintain dependencies for Composer
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "hellopablo"
labels:
- "dependencies"
- "php"
29 changes: 29 additions & 0 deletions .github/workflows/build_and_test.yml
@@ -0,0 +1,29 @@
name: build_and_test
on: [ push ]
jobs:
test:
name: build_and_test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 7.3

- name: Cache Composer dependencies
uses: actions/cache@v1
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}

- name: Install Composer dependencies
run: composer install

- name: Run tests
run: composer test
env:
PRIVATE_KEY: 123abc
5 changes: 5 additions & 0 deletions .phpstan/config.neon
@@ -0,0 +1,5 @@
parameters:
level: 0
paths:
- ../src
- ../tests
9 changes: 9 additions & 0 deletions LICENSE
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2021 Shed Collective Ltd hello@shedcollective.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions README.md
@@ -0,0 +1,7 @@
# Analytics Module for Nails

![license](https://img.shields.io/badge/license-MIT-green.svg)
[![tests](https://github.com/nails/module-analytics/actions/workflows/build_and_test.yml/badge.svg )](https://github.com/nails/module-analytics/actions)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nails/module-analytics/badges/quality-score.png)](https://scrutinizer-ci.com/g/nails/module-analytics)

This module provides a unified API for loading, configuring, and using analytic platforms.
49 changes: 49 additions & 0 deletions composer.json
@@ -0,0 +1,49 @@
{
"name": "nails/module-analytics",
"keywords": [],
"homepage": "http://nailsapp.co.uk/modules/analytics",
"description": "This module provides a unified API for loading, configuring, and using analytic platforms.",
"license": "MIT",
"authors": [
{
"name": "Pablo de la Pena",
"email": "p@nailsapp.co.uk",
"homepage": "http://nailsapp.co.uk",
"role": "Developer"
}
],
"support": {
"email": "hello@nailsapp.co.uk"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"nails\/common": "dev-develop"
},
"require-dev": {
"phpunit/phpunit": "9.*",
"phpstan/phpstan": "0.*"
},
"scripts": {
"test": "./vendor/bin/phpunit",
"analyse": "./vendor/bin/phpstan analyse -c .phpstan/config.neon"
},
"autoload": {
"psr-4": {
"Nails\\Analytics\\": "src\/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\Analytics\\": "tests\/"
}
},
"extra": {
"nails": {
"moduleName": "analytics",
"type": "module",
"namespace": "Nails\\Analytics\\",
"data": {}
}
}
}
7 changes: 7 additions & 0 deletions phpunit.xml
@@ -0,0 +1,7 @@
<phpunit bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 15 additions & 0 deletions services/services.php
@@ -0,0 +1,15 @@
<?php

use Nails\Analytics\Service;

return [
'services' => [
'Drivers' => function (): Service\Drivers {
if (class_exists('\App\Analytics\Service\Drivers')) {
return new \App\Analytics\Service\Drivers();
} else {
return new Service\Drivers();
}
},
],
];
18 changes: 18 additions & 0 deletions src/Constants.php
@@ -0,0 +1,18 @@
<?php

namespace Nails\Analytics;

/**
* Class Constants
*
* @package Nails\Analytics
*/
class Constants
{
/**
* The slug for this module
*
* @var string
*/
const MODULE_SLUG = 'nails/module-analytics';
}
45 changes: 45 additions & 0 deletions src/Event/Listener/System/Ready.php
@@ -0,0 +1,45 @@
<?php

namespace Nails\Analytics\Event\Listener\System;

use Nails\Analytics\Constants;
use Nails\Common\Events;
use Nails\Common\Events\Subscription;
use Nails\Common\Exception\NailsException;
use Nails\Factory;
use ReflectionException;

/**
* Class Ready
*
* @package Nails\Analytics\Event\Listener\System
*/
class Ready extends Subscription
{
/**
* Ready constructor.
*
* @throws NailsException
* @throws ReflectionException
*/
public function __construct()
{
$this
->setEvent(Events::SYSTEM_READY)
->setNamespace(Events::getEventNamespace())
->setCallback([$this, 'execute']);
}

// --------------------------------------------------------------------------

public function execute(): void
{
/** @var \Nails\Analytics\Service\Drivers $oDrivers */
$oDrivers = Factory::service('Drivers', Constants::MODULE_SLUG);
foreach ($oDrivers->getAll() as $oDriver) {
/** @var \Nails\Analytics\Interfaces\Driver $oInstance */
$oInstance = $oDrivers->getInstance($oDriver);
$oInstance->boot();
}
}
}
8 changes: 8 additions & 0 deletions src/Interfaces/Driver.php
@@ -0,0 +1,8 @@
<?php

namespace Nails\Analytics\Interfaces;

interface Driver
{
public function boot(): self;
}
18 changes: 18 additions & 0 deletions src/Service/Drivers.php
@@ -0,0 +1,18 @@
<?php

namespace Nails\Analytics\Service;

use Nails\Analytics\Constants;
use Nails\Analytics\Interfaces\Driver;
use Nails\Common\Model\BaseDriver;

/**
* Class Drivers
*
* @package Nails\Analytics\Service
*/
class Drivers extends BaseDriver
{
protected $sModule = Constants::MODULE_SLUG;
protected $sMustImplement = Driver::class;
}
3 changes: 3 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,3 @@
<?php

require 'vendor/autoload.php';

0 comments on commit 8976b50

Please sign in to comment.