Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from apility/feature/nf-console-deprecation
Browse files Browse the repository at this point in the history
Refactor Console handler
  • Loading branch information
thomas-alrek authored Jun 17, 2019
2 parents ceedd46 + 957f698 commit 945b809
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 23 deletions.
26 changes: 12 additions & 14 deletions src/NF.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Netflex\Site\Commerce;
use Netflex\Site\Search;
use Netflex\Site\JWT;
use PhpConsole\Handler;
use Netflex\Site\Console;

class NF
{
Expand All @@ -35,7 +35,10 @@ class NF
public static $config;
/** @var array[string]string */
public static $routes;
/** @var Handler */
/**
* @deprecated 1.0.11
* @var Console
* */
public static $console;
/** @var string */
public static $sitename;
Expand Down Expand Up @@ -83,7 +86,7 @@ public static function init($site = null, $branch = null, $path = [])
self::clearCache();
}

self::$console = self::startPhpConsole();
self::$console = Console::getInstance();
self::$site = new Site();

// Datastore for Netflex
Expand Down Expand Up @@ -165,17 +168,13 @@ public static function nfPath($file)
/**
* Instantiates a PHPConsole session
*
* @return PhpConsole
* @deprecated 1.0.11
* @return Console
*/
public static function startPhpConsole()
{
$console = null;
if (getenv('ENV') !== 'master') {
$console = Handler::getInstance();
$console->getConnector()->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']);
$console->start();
}
return $console;
trigger_error('NF::startPhpConsole is deprecated', E_USER_DEPRECATED);
return new Console();
}

/**
Expand All @@ -186,9 +185,8 @@ public static function startPhpConsole()
*/
public static function debug($text, $label = null)
{
if (self::$console) {
self::$console->debug($text, $label);
}
$console = Console::getInstance();
$console->log($text, $label);
}

/**
Expand Down
61 changes: 61 additions & 0 deletions src/Netflex/Site/Console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Netflex\Site;

use PhpConsole\Handler;

class Console {
/** @var Handler */
private $handler;

/** @var static */
private static $instance;

protected function __construct()
{
if (getenv('ENV') !== 'master') {
$this->handler = Handler::getInstance();;
$this->handler->getConnector()->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']);
$this->handler->start();
}
}

/**
* Instantiates a Console instance
*
* @return Console
*/
public static function getInstance () {
if (!self::$instance) {
self::$instance = new static;
}

return self::$instance;
}

/**
* Logs the text to console (if not in production)
*
* @param string $text
* @param string $labels One or more labels separated by .
* @return void
*/
public function log ($text, $labels = null) {
if ($this->handler) {
$this->handler->debug($text, $labels);
}
}

/**
* @deprecated 1.0.11
*
* @param string $text
* @param string $label
* @return void
*/
public function debug ($text, $label)
{
trigger_error('NF::$console->debug is deprecated', E_USER_DEPRECATED);
return $this->log($text, $label);
}
}
2 changes: 0 additions & 2 deletions tests/mocks/NF.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
require_once(__DIR__ . '/Cache.php');
require_once(__DIR__ . '/Guzzle.php');
require_once(__DIR__ . '/Site.php');
require_once(__DIR__ . '/PHPConsole.php');

NF::$capi = new MockGuzzle();
NF::$cache = new MockCache();
NF::$site = new MockSite();
NF::$console = new MockPHPConsole();
NF::$site_root = __DIR__ . '/project/';
7 changes: 0 additions & 7 deletions tests/mocks/PHPConsole.php

This file was deleted.

0 comments on commit 945b809

Please sign in to comment.