Skip to content

Commit

Permalink
first version after module separation
Browse files Browse the repository at this point in the history
  • Loading branch information
hadi committed Nov 2, 2017
1 parent 86d784d commit ad11065
Show file tree
Hide file tree
Showing 13 changed files with 1,110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Eclipse
.project
.settings
/.buildpath

# Composer
/vendor/
composer.lock
composer-setup.php
composer.phar

# Project
storage/tenant

# KDE
.directory
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: php
php:
- '5.6'

mysql:
database: test
username: root
encoding: utf8

before_install:
- sudo apt-get update > /dev/null
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"

install:
- php composer.phar install

script:
- cd tests
- php run.php
- php coverage-checker.php clover.xml 70

675 changes: 675 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name" : "pluf/tenant",
"description" : "A pluf module to manage current tenant",
"type" : "library",
"license" : "MIT",
"authors" : [{
"name" : "Mostafa Barmshory",
"email" : "[email protected]",
"homepage" : "http://dpq.co.ir",
"role" : "developer"
}, {
"name" : "Mohammad Hadi Mansouri",
"email" : "[email protected]",
"homepage" : "http://dpq.co.ir",
"role" : "developer"
}
],
"minimum-stability" : "stable",
"require" : {
"pluf/core" : "^2.1.0",
"pluf/user" : "^2.1.0"
},
"require-dev" : {
"phpunit/phpunit" : "^5.7.14",
"phpunit/php-invoker" : "^1.1",
"phpunit/dbunit" : "^2.0",
"phpunit/phpunit-story" : "^1.0"
},
"include-path" : [
"src/"
],
"homepage" : "https://github.com/pluf/tenant",
"support" : {
"email" : "[email protected]",
"issues" : "https://github.com/pluf/tenant/issues",
"forum" : "https://github.com/pluf/tenant",
"wiki" : "https://github.com/pluf/tenant/wiki",
"source" : "https://github.com/pluf/tenant"
},
"keywords" : [
"pluf",
"php",
"pluf-module",
"tenant"
]
}
47 changes: 47 additions & 0 deletions src/Tenant/Monitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class Tenant_Monitor
{

public static function count ()
{
// XXX: maso, 1395
}

public static function storage ()
{
$result = array(
'value' => 35,
'min' => 0,
'max' => Config_Service::get('storage.size.max', 10485760), // 10Mb
'unit' => 'byte',
'interval' => 1000000,
'type' => 'scalar'
);
// maso, 2017: find storage size
// FIXME: maso, 2017: using php native if is not linux
$file_directory = Pluf_Tenant::storagePath();
// $output = exec('du -sk ' . $file_directory);
// $result['value'] = trim(str_replace($file_directory, '', $output)) * 1024;
$result['value'] = Pluf_Shortcuts_folderSize($file_directory);
return $result;
}
}

80 changes: 80 additions & 0 deletions src/Tenant/Views.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');

/**
* لایه نمایش مدیریت گروه‌ها را به صورت پیش فرض ایجاد می‌کند
*
* @author maso
*
*/
class Tenant_Views extends Pluf_Views
{

/**
*
* @param unknown_type $request
* @param unknown_type $match
*/
public static function current ($request, $match)
{
return new Pluf_HTTP_Response_Json($request->tenant);
}

/**
*
* @param unknown_type $request
* @param unknown_type $match
*/
public static function update ($request, $match)
{
$model = $request->tenant;
$form = Pluf_Shortcuts_GetFormForModel($model, $request->REQUEST,
array());
return new Pluf_HTTP_Response_Json($form->save());
}

/**
*
* @param unknown_type $request
* @param unknown_type $match
*/
public static function get ($request, $match)
{
return Tenant_Views::current($request, $match);
}

/**
*
* @param unknown_type $request
* @param unknown_type $match
*/
public function delete ($request, $match)
{
$model = $request->tenant;
$model2 = Pluf_Shortcuts_GetObjectOr404('Pluf_Tenant', $request->tenant->id);
$model2->delete();
// XXX: maso, 1395: delete permisions
// XXX: maso, 1395: delete files
// XXX: maso, 1395: delete Settings, configs
// XXX: maso, 1395: emite signal
return new Pluf_HTTP_Response_Json($model);
}
}
14 changes: 14 additions & 0 deletions src/Tenant/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Tenant",
"version": "2.1.9",
"title": "Tenant Management",
"permisson": [],
"monitor":[{
"bean": "tenant",
"property": "storage",
"title": "Storage size",
"description": "Storage size of the tenant.",
"function": "Tenant_Monitor::Storage",
"level": 1
}]
}
19 changes: 19 additions & 0 deletions src/Tenant/relations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
return array ();
90 changes: 90 additions & 0 deletions src/Tenant/urls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/*
* This file is part of Pluf Framework, a simple PHP Application Framework.
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
return array(
array(
'regex' => '#^$#',
'model' => 'Tenant_Views',
'method' => 'current',
'http-method' => 'GET',
'precond' => array()
),
array(
'regex' => '#^$#',
'model' => 'Tenant_Views',
'method' => 'update',
'http-method' => 'POST',
'precond' => array(
'Pluf_Precondition::ownerRequired'
)
),
array(
'regex' => '#^$#',
'model' => 'Tenant_Views',
'method' => 'delete',
'http-method' => 'DELETE',
'precond' => array(
'Pluf_Precondition::ownerRequired'
)
)
// array(
// 'regex' => '#^/find$#',
// 'model' => 'Tenant_Views',
// 'method' => 'find',
// 'http-method' => 'GET',
// 'precond' => array(
// 'Pluf_Precondition::loginRequired'
// )
// ),
// array(
// 'regex' => '#^/new$#',
// 'model' => 'Tenant_Views',
// 'method' => 'create',
// 'http-method' => 'POST',
// 'precond' => array(
// 'Pluf_Precondition::loginRequired'
// )
// ),
// array(
// 'regex' => '#^/(?P<id>.+)$#',
// 'model' => 'Tenant_Views',
// 'method' => 'get',
// 'http-method' => 'GET',
// 'precond' => array(
// 'Pluf_Precondition::loginRequired'
// )
// ),
// array(
// 'regex' => '#^/(?P<id>.+)$#',
// 'model' => 'Tenant_Views',
// 'method' => 'update',
// 'http-method' => 'POST',
// 'precond' => array(
// 'Pluf_Precondition::loginRequired'
// )
// ),
// array(
// 'regex' => '#^/(?P<id>.+)$#',
// 'model' => 'Tenant_Views',
// 'method' => 'delete',
// 'http-method' => 'DELETE',
// 'precond' => array(
// 'Pluf_Precondition::loginRequired'
// )
// )
);
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/clover.xml
31 changes: 31 additions & 0 deletions tests/coverage-checker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
// coverage-checker.php
$inputFile = $argv[1];
$percentage = min(100, max(0, (int) $argv[2]));

if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}

if (!$percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
}

$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//metrics');
$totalElements = 0;
$checkedElements = 0;

foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}

$coverage = ($checkedElements / $totalElements) * 100;

if ($coverage < $percentage) {
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
exit(1);
}

echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;
8 changes: 8 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="pluf/tenant">
<directory>./Tenant_Api/</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit ad11065

Please sign in to comment.