Skip to content

Commit

Permalink
#7 change namespaces in core system
Browse files Browse the repository at this point in the history
  • Loading branch information
xandros15 committed May 25, 2016
1 parent 2c349bd commit f75f924
Show file tree
Hide file tree
Showing 30 changed files with 102 additions and 12,435 deletions.
4 changes: 2 additions & 2 deletions library/components/Filter.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace library;
namespace Saya\Components;

use library\helper\IRCHelper;
use Saya\Components\Helper\IRCHelper;
use Symfony\Component\Process\Process;

class Filter
Expand Down
2 changes: 1 addition & 1 deletion library/components/FunctionHash.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace library;
namespace Saya\Components;

use ReflectionFunction;
use SplFileObject;
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 17:01
*/

namespace library\format;
namespace Saya\Components\Format;

class Color implements Format
{
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/ColorParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 13:08
*/

namespace library\format;
namespace Saya\Components\Format;


class ColorParser extends Color
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/ColorTricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 13:09
*/

namespace library\format;
namespace Saya\Components\Format;


class ColorTricks extends Color
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 01:11
*/

namespace library\format;
namespace Saya\Components\Format;


Interface Format
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/InvalidColorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 01:34
*/

namespace library\format;
namespace Saya\Components\Format;


use InvalidArgumentException;
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 17:05
*/

namespace library\format;
namespace Saya\Components\Format;


class Text implements Format
Expand Down
2 changes: 1 addition & 1 deletion library/components/format/TextParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 18:34
*/

namespace library\format;
namespace Saya\Components\Format;


class TextParser extends Text
Expand Down
2 changes: 1 addition & 1 deletion library/components/helper/IRCHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace library\helper;
namespace Saya\Components\Helper;

/* @todo
* change colors method
Expand Down
3 changes: 1 addition & 2 deletions library/components/helper/ServerHelper.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

namespace library\helper;
namespace Saya\Components\Helper;

use Exception;

class ServerHelper
{

/**
* @param string $ports
* @return array
Expand Down
3 changes: 1 addition & 2 deletions library/components/helper/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* Time: 03:09
*/

namespace library\helper;

namespace Saya\Components\Helper;

class StringHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace library\Debugger;
namespace Saya\Components\Logger;

use DateTime;
use DateTimeZone;
use Exception;
use library\debugger\LoggerInterface;

class Core
{
Expand Down Expand Up @@ -104,9 +103,9 @@ protected function flatten(array $array, $prefix)

protected function setDatetime($timezoneName = 'UTC')
{
$timezone = new DateTimeZone($timezoneName);
$datetime = new DateTime('now', $timezone);
$this->datetime = $datetime;
$timezone = new DateTimeZone($timezoneName);
$datetime = new DateTime('now', $timezone);
$this->datetime = $datetime;
$this->timezoneName = $timezoneName;
return $this;
}
Expand All @@ -116,10 +115,14 @@ protected function getPrefix($type)
$prefix = $this->getTimestamp();

switch ($type) {
case LoggerInterface::ERROR: return $prefix .= ' (!ERROR): ';
case LoggerInterface::WARNING: return $prefix .= ' (WARNING): ';
case LoggerInterface::INFO: return $prefix .= ' (INFO): ';
case LoggerInterface::SUCCESS: return $prefix .= ' (SUCCESS): ';
case LoggerInterface::ERROR:
return $prefix .= ' (!ERROR): ';
case LoggerInterface::WARNING:
return $prefix .= ' (WARNING): ';
case LoggerInterface::INFO:
return $prefix .= ' (INFO): ';
case LoggerInterface::SUCCESS:
return $prefix .= ' (SUCCESS): ';
}
}

Expand All @@ -132,8 +135,8 @@ protected function setFilename($file)
} elseif (!is_writable($file)) {
throw new Exception("{$file}: write: permission denied");
}
$fileinfo = pathinfo($file);
$this->ext = $fileinfo['extension'];
$fileinfo = pathinfo($file);
$this->ext = $fileinfo['extension'];
$this->filename = $fileinfo['filename'];
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

namespace library\Debugger;
namespace Saya\Components\Logger;

use library\debugger\Core;
use library\botInterface\LoggerInterface as LoggerInterface;
use Exception;

class LoggerInterface extends Core implements LoggerInterface
class Logger extends Core implements LoggerInterface
{

public static function add($message, $type = self::INFO)
{
parent::add($message, $type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

namespace library\BotInterface;
namespace Saya\Components\Logger;

interface LoggerInterface
{

public static function add($message, $type);

public static function setLogger($filename, $path, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion library/components/ui/Cli.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace library\Ui;
namespace Saya\Components\Ui;


class Cli
Expand Down
53 changes: 30 additions & 23 deletions library/core/Bot.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
<?php

namespace library;
namespace Saya\Core;

use library\Module;
use library\Server;
use library\Configuration as Config;
use library\Filter;
use library\constants\IRC;
use Saya\Core\Client\Module;
use Saya\Core\Client\User;
use Saya\Core\Connection\Server;
use Saya\Core\Input\Textline;
use Saya\Core\Configuration\Configuration as Config;
use Saya\Components\Filter;
use ReflectionClass;
use Exception;
use library\debugger\LoggerInterface;

/* Interfaces */
use Saya\Components\Logger\Logger;

class Bot
{
public
$channelList = [],
/** @var \Library\Module */
/**
* @var Module
*/
$module = [];
private
$buffer = [],
/** @var \Library\Chatter\Textline */
$chat = null,
$messageToSend = 0,
$timeLastSend = 0,
/** @var \Library\Server */
$server,
$numberOfReconnects = 0;
$buffer = [];
/**
* @var Textline
*/
private $chat;
private $messageToSend = 0;
private $timeLastSend = 0;
/**
* @var Server
*/
private $server;
private $numberOfReconnects = 0;

public function connectToServer()
{
Expand Down Expand Up @@ -112,7 +117,7 @@ public function fillBuffer($text, $type, $target = null, $prio = false)
$message = IRC::PONG . ' ' . $text;
break;
default:
return;
return false;
}
if (strlen($message) > 508) {
$lastWhiteSpace = strrpos(substr($message, 0, 508), ' ');
Expand All @@ -128,6 +133,7 @@ public function fillBuffer($text, $type, $target = null, $prio = false)
while ($prio && $this->buffer) {
$this->flushBuffer();
}
return true;
}

public function getMask()
Expand Down Expand Up @@ -212,11 +218,12 @@ private function flushBuffer()

private function loadModule(array $module)
{
$namespace = 'module';
$namespace = 'basic';
$user = new User($this->server);

foreach ($module as $moduleName) {
LoggerInterface::add('load ' . $moduleName . ' module', LoggerInterface::INFO); //fwrite(STDOUT ,'load ' . $moduleName . ' module... ');
Logger::add('load ' . $moduleName . ' module',
Logger::INFO); //fwrite(STDOUT ,'load ' . $moduleName . ' module... ');
$reflector = new ReflectionClass("{$namespace}\\{$moduleName}");
$instance = $reflector->newInstance();
$name = $reflector->getShortName();
Expand All @@ -227,7 +234,7 @@ private function loadModule(array $module)
$this->module[$name]->setIRCBot($this);
$this->module[$name]->setUser($user);
$this->module[$name]->loadSettings();
echo LoggerInterface::add('done', LoggerInterface::INFO);
echo Logger::add('done', Logger::INFO);
}
}

Expand Down Expand Up @@ -265,7 +272,7 @@ private function sendDataToServer($data)
private function setupBot()
{
(new Config())->simpleConfiguration();
LoggerInterface::setLogger('debug.log', '.', Config::DEFAULT_TIMEZONE);
Logger::setLogger('debug.log', '.', Config::DEFAULT_TIMEZONE);
$server = new Server();
$server->getTextline();
$server->setHost(Config::$server);
Expand Down
2 changes: 1 addition & 1 deletion library/core/IRC.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace library\Constants;
namespace Saya\Core;

class IRC
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace library;
namespace Saya\Core\Client;

class Channel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace library;
namespace Saya\Core\Client;

use Closure;
use DOMDocument;
use Exception;
use library\Bot;
use library\helper\UrlHelper;
use library\FunctionHash;
use library\Configuration as Config;
use library\constants\IRC;
use R;
use Saya\Core\Bot;
use Saya\Core\Client\UrlHelper;
use Saya\Components\FunctionHash;
use Saya\Core\Configuration\Configuration as Config;
use Saya\Core\IRC;
use RedBeanPHP\R;
use ReflectionClass;

abstract class Module
Expand All @@ -28,12 +28,13 @@ abstract class Module


/**
* @var \library\Bot
* @var Bot
*/
protected $bot = null;
protected $bot;
/**
* @var User
*/
protected $ctx;
protected $user;
protected $commands = [];
protected $executeTime = [];
Expand Down Expand Up @@ -432,7 +433,6 @@ protected function checkCommand($command, $mode)
*/
protected static function RedBeanConnect($dbname, $frozen = true)
{
require_once(implode(DIRECTORY_SEPARATOR, [ROOT_DIR, 'library', 'database', 'rb.php']));
if (isset(R::$toolboxes[$dbname])) {
R::selectDatabase($dbname);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace library\helper;
namespace Saya\Core\Client;

class UrlHelper
{
Expand Down
Loading

0 comments on commit f75f924

Please sign in to comment.