Skip to content

Commit

Permalink
(feat): general refactoring work for the DI
Browse files Browse the repository at this point in the history
  • Loading branch information
markharding committed Feb 24, 2016
1 parent 009b98b commit 68161bc
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 12 deletions.
19 changes: 19 additions & 0 deletions Components/Controller.php
@@ -0,0 +1,19 @@
<?php
/**
* Controller class
*/

namespace Minds\Components;

class Controller {

protected $di;
protected $config;

public function __construct()
{
$this->di = Minds\Core\Di\Di::_();
$this->config = $this->di->get('Config');
}

}
9 changes: 5 additions & 4 deletions Controllers/api/v1/admin/pages.php
Expand Up @@ -8,14 +8,15 @@
*/
namespace Minds\Controllers\api\v1\admin;

use Minds\Components\Controller;
use Minds\Core;
use Minds\Core\Di\Di;
use Minds\Helpers;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class pages implements Interfaces\Api, Interfaces\ApiIgnorePam
class pages extends Controller implements Interfaces\Api, Interfaces\ApiIgnorePam
{
/**
*
Expand All @@ -35,7 +36,7 @@ public function get($pages)
];
}
} else {
$pages = Di::_()->get('PagesManager')->getPages();
$pages = $this->di->get('PagesManager')->getPages();
$response = [
'pages' => Factory::exportable($pages)
];
Expand Down Expand Up @@ -77,8 +78,8 @@ public function post($pages)
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
$resized = get_resized_image_from_uploaded_file('file', 2000);
$path = $pages[0];
$filepath = Core\Config::_()->dataroot . "page_banners/" . $page->getPath() . ".jpg";
@mkdir(Core\Config::_()->dataroot . "page_banners", 0777, true);
$filepath = $this->config->dataroot . "page_banners/" . $page->getPath() . ".jpg";
@mkdir($this->config->dataroot . "page_banners", 0777, true);

$f = fopen($filepath, "w+b");
fwrite($f, $resized);
Expand Down
11 changes: 6 additions & 5 deletions Controllers/api/v1/block.php
Expand Up @@ -7,12 +7,13 @@
*/
namespace Minds\Controllers\api\v1;

use Minds\Components\Controller;
use Minds\Core;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class block implements Interfaces\Api, Interfaces\ApiIgnorePam
class block extends Controller implements Interfaces\Api, Interfaces\ApiIgnorePam
{
/**
* Return a list of your blocked users
Expand All @@ -30,7 +31,7 @@ public function get($pages)
$limit = isset($_GET['limit']) ? $_GET['limit'] : 12;
$offset = isset($_GET['offset']) ? $_GET['offset'] : "";

$block = Core\Security\ACL\Block::_();
$block = $this->di->get('Security\ACL\Block');
$guids = $block->getBlockList(Core\Session::getLoggedinUser(), $limit, $offset);

if ($guids) {
Expand All @@ -39,7 +40,7 @@ public function get($pages)
}
break;
case is_numeric($pages[0]):
$block = Core\Security\ACL\Block::_();
$block = $this->di->get('Security\ACL\Block');
$response['blocked'] = $block->isBlocked($pages[0]);
break;
}
Expand All @@ -62,7 +63,7 @@ public function post($pages)
*/
public function put($pages)
{
$block = Core\Security\ACL\Block::_();
$block = $this->di->get('Security\ACL\Block');
$block->block($pages[0]);

return Factory::response(array());
Expand All @@ -73,7 +74,7 @@ public function put($pages)
*/
public function delete($pages)
{
$block = Core\Security\ACL\Block::_();
$block = $this->di->get('Security\ACL\Block');
$block->unBlock($pages[0]);

return Factory::response(array());
Expand Down
30 changes: 30 additions & 0 deletions Core/Boost/BoostProvider.php
@@ -0,0 +1,30 @@
<?php
/**
* Minds Boost Provider
*/

namespace Minds\Core\Boost;

use Minds\Core\Di\Provider;

class BoostProvider extends Provider
{

public function register()
{
$this->di->bind('Boost\Network', function($di){
return new Network(Data\Client::build('MongoDB'), new Data\Call('entities_by_time'));
}, ['useFactory'=>true]);
$this->di->bind('Boost\Newsfeed', function($di){
return new Newsfeed(Data\Client::build('MongoDB'), new Data\Call('entities_by_time'));
}, ['useFactory'=>true]);
$this->di->bind('Boost\Content', function($di){
return new Content(Data\Client::build('MongoDB'), new Data\Call('entities_by_time'));
}, ['useFactory'=>true]);

$this->di->bind('Boost\Peer', function($di){
return new Peer();
}, ['useFactory'=>true]);
}

}
4 changes: 1 addition & 3 deletions Core/Boost/Network.php
Expand Up @@ -19,9 +19,7 @@ class Network implements BoostHandlerInterface

protected $tries = 0;

public function __construct($options = array(),
Data\Interfaces\ClientInterface $mongo = null,
Data\Call $db = null)
public function __construct($options = [], Data\Interfaces\ClientInterface $mongo = null, Data\Call $db = null)
{
$this->mongo = $mongo ?: Data\Client::build('MongoDB');
$this->db = $db ?: new Data\Call('entities_by_time');
Expand Down
47 changes: 47 additions & 0 deletions Core/Data/DataProvider.php
@@ -0,0 +1,47 @@
<?php
/**
* Minds dataroot Provider
*/

namespace Minds\Core\Data;

use Minds\Core\Di\Provider;

class DataProvider extends Provider
{

public function register()
{
/**
* Cache bindings
*/
$this->di->bind('Cache', function($di){
return $di->get('Cache\Redis');
}, ['useFactory'=>true]);
$this->di->bind('Cache\Redis', function($di){
return new Cache\Redis();
}, ['useFactory'=>true]);
$this->di->bind('Cache\Apcu', function($di){
return new Cache\Apcu();
}, ['useFactory'=>true]);
/**
* Database bindings
*/
$this->di->bind('Database', function($di){
return $di->get('Database\Cassandra');
}, ['useFactory'=>true]);
$this->di->bind('Database\Cassandra', function($di){
return new Data\Call();
}, ['useFactory'=>true]);
$this->di->bind('Database\MongoDB', function($di){
return new Data\MongoDB\Client();
}, ['useFactory'=>true]);
$this->di->bind('Database\Neo4j', function($di){
return new Data\Neo4j\Client();
}, ['useFactory'=>true]);
$this->di->bind('Database\ElasticSearch', function($di){
return new Data\ElasticSearch\Client();
}, ['useFactory'=>true]);
}

}
38 changes: 38 additions & 0 deletions settings.json
@@ -0,0 +1,38 @@
{

"cassandra": {
"keyspace": "minds",
"servers": [ "127.0.0.1" ],
"cql_servers": [ "127.0.0.1:9042" ]
},

"installed": true,

"path": "/var/www/Minds/",
"dataroot": "/data/",

"default_site": "01",
"site_id": "01",
"__site_secret__": "abc123xyz789",

"system_cache_path": "/tmp/elgg_system_cache/",

"elasticsearch_server": "http://localhost:9200/",
"elasticsearch_prefix": "mehmac_",

"broken_mta": false,

"min_password_length": 6,
"minusername": 2,

"icon_sizes": {
"topbar": { "w": 16, "h": 16, "square": true, "upscale": true },
"tiny": { "w": 25, "h": 25, "square": true, "upscale": true },
"small": { "w": 40, "h": 40, "square": true, "upscale": true },
"medium": { "w": 100, "h": 100, "square": true, "upscale": true },
"large": { "w": 425, "h": 425, "square": false, "upscale": false },
"master": { "w": 550, "h": 550, "square": false, "upscale": false }
}

}

0 comments on commit 68161bc

Please sign in to comment.