diff --git a/Math/Number/Integer.php b/Math/Number/Integer.php index 4f7677897..7705f7fe9 100644 --- a/Math/Number/Integer.php +++ b/Math/Number/Integer.php @@ -71,7 +71,17 @@ class Integer return 1; } - public static function trialFactorization(int $value) + /** + * Trial factorization. + * + * @param int $value Integer to factorize + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function trialFactorization(int $value) : array { if ($value < 2) { return []; @@ -98,31 +108,65 @@ class Integer return $factors; } - public static function pollardsRho($value, $x = 2, $factor = 1, $cycleSize = 2, $xFixed = 2) + /** + * Pollard's Rho. + * + * Integer factorization algorithm + * + * @param int $n Integer to factorize + * @param int $x Used for g(x) = (x^2 + 1) mod n + * @param int $factor Period for repetition + * @param int $cycleSize Cycle size + * @param int $y Fixed value for g(x) = g(y) mod p + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function pollardsRho(int $n, int $x = 2, int $factor = 1, int $cycleSize = 2, int $y = 2) : int { while ($factor === 1) { for ($i = 1; $i < $cycleSize && $factor <= 1; $i++) { - $x = ($x * $x + 1) % $value; - $factor = self::greatestCommonDivisor($x - $xFixed, $value); + $x = ($x * $x + 1) % $n; + $factor = self::greatestCommonDivisor($x - $y, $n); } $cycleSize *= 2; - $xFixed = $x; + $y = $x; } return $factor; } - public static function fermatFactor(int $value) + /** + * Fermat factorization of odd integers. + * + * @param int $value Integer to factorize + * @param int $limit Max amount of iterations + * + * @return int + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function fermatFactor(int $value, int $limit = 1000000) : int { - $a = $value; - $b2 = $a * $a - $value; + if(($value % 2) !== 0) { + throw new \Exception('Only odd integers are allowed'); + } - while (abs((int) round(sqrt($b2), 0) - sqrt($b2)) > 0.0001) { + $a = (int) ceil(sqrt($value)); + $b2 = $a * $a - $value; + $i = 1; + + while (!Numbers::isSquare($b2) && $i < $limit) { $a += 1; $b2 = $a * $a - $value; } - return $a - sqrt($b2); + return (int) round($a - sqrt($b2)); } } \ No newline at end of file diff --git a/Message/Mail/Imap.php b/Message/Mail/Imap.php index 5e187b01d..61041c7d4 100644 --- a/Message/Mail/Imap.php +++ b/Message/Mail/Imap.php @@ -15,16 +15,60 @@ */ namespace phpOMS\Message\Mail; +/** + * Imap mail class. + * + * @category Framework + * @package phpOMS\Message\Mail + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ class Imap extends Mail { + /** + * Mail inbox. + * + * @var resource + * @since 1.0.0 + */ private $inbox = null; + + /** + * Host. + * + * @var string + * @since 1.0.0 + */ private $host = ''; + /** + * User. + * + * @var string + * @since 1.0.0 + */ + private $user = ''; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __construct() { parent::__construct(MailType::IMAP); } + /** + * Destructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __destruct() { if (isset($this->inbox)) { @@ -32,103 +76,273 @@ class Imap extends Mail } } + /** + * Connect to inbox. + * + * @param string $host Host + * @param string $user User + * @param string $password Password + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function connect($host, $user, $password) { $this->host = $host; + $this->user = $user; $this->inbox = imap_open($host, $user, $password); return !($this->inbox === false); } - public function getBoxes() + /** + * Get boxes. + * + * @param string $pattern Pattern for boxes + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getBoxes(string $pattern = '*') : array { - return imap_list($this->inbox, $this->host, '*'); + return imap_list($this->inbox, $this->host, $pattern); } + /** + * Get inbox quota. + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getQuota() { return imap_get_quotaroot($this->inbox, "INBOX"); } - public function getInbox(string $option = 'ALL') : array + /** + * Get inbox overview. + * + * @param string $option Inbox option (imap_search creterias) + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxOverview(string $option = 'ALL') : array { $ids = imap_search($this->inbox, $option, SE_FREE, 'UTF-8'); return is_array($ids) ? imap_fetch_overview($this->inbox, implode(',', $ids)) : []; } - public function getEmail($id) + /** + * Get email. + * + * @param mixed $id mail id + * + * @return Mail + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getEmail($id) : Mail { - return [ - 'overview' => imap_fetch_overview($this->inbox, $id), - 'body' => imap_fetchbody($this->inbox, $id, 2), - 'encoding' => imap_fetchstructure($this->inbox, $id), - ]; + $mail = new Mail($id); + $mail->setOverview(imap_fetch_overview($this->inbox, $id)); + $mail->setBody(imap_fetchbody($this->inbox, $id, 2)); + $mail->setEncoding(imap_fetchstructure($this->inbox, $id)); + + return $mail; } - public function getInboxAll() + /** + * Get all inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxAll() : array { - return $this->getInbox('ALL'); + return $this->getInboxOverview('ALL'); } - public function getInboxNew() + /** + * Get all new inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxNew() : array { - return $this->getInbox('NEW'); + return $this->getInboxOverview('NEW'); } - public function getInboxFrom(string $from) + /** + * Get all inbox messages from a person. + * + * @param string $from Messages from + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxFrom(string $from) : array { - return $this->getInbox('FROM "' . $from . '"'); + return $this->getInboxOverview('FROM "' . $from . '"'); } - public function getInboxTo(string $to) + /** + * Get all inbox messages to a person. + * + * @param string $to Messages to + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxTo(string $to) : array { - return $this->getInbox('TO "' . $to . '"'); + return $this->getInboxOverview('TO "' . $to . '"'); } - public function getInboxCc(string $cc) + /** + * Get all inbox messages cc a person. + * + * @param string $cc Messages cc + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxCc(string $cc) : array { - return $this->getInbox('CC "' . $cc . '"'); + return $this->getInboxOverview('CC "' . $cc . '"'); } - public function getInboxBcc(string $bcc) + /** + * Get all inbox messages bcc a person. + * + * @param string $bcc Messages bcc + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxBcc(string $bcc) : array { - return $this->getInbox('BCC "' . $bcc . '"'); + return $this->getInboxOverview('BCC "' . $bcc . '"'); } - public function getInboxAnswered() + /** + * Get all answered inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxAnswered() : array { - return $this->getInbox('ANSWERED'); + return $this->getInboxOverview('ANSWERED'); } - public function getInboxSubject(string $subject) + /** + * Get all inbox messages with a certain subject. + * + * @param string $subject Subject + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxSubject(string $subject) : array { - return $this->getInbox('SUBJECT "' . $subject . '"'); + return $this->getInboxOverview('SUBJECT "' . $subject . '"'); } - public function getInboxSince(\DateTime $since) + /** + * Get all inbox messages from a certain date onwards. + * + * @param \DateTime $since Messages since + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxSince(\DateTime $since) : array { - return $this->getInbox('SINCE "' . $since->format('d-M-Y') . '"'); + return $this->getInboxOverview('SINCE "' . $since->format('d-M-Y') . '"'); } - public function getInboxUnseen() + /** + * Get all unseen inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxUnseen() : array { - return $this->getInbox('UNSEEN'); + return $this->getInboxOverview('UNSEEN'); } - public function getInboxSeen() + /** + * Get all seen inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxSeen() : array { - return $this->getInbox('SEEN'); + return $this->getInboxOverview('SEEN'); } - public function getInboxDeleted() + /** + * Get all deleted inbox messages. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxDeleted() : array { - return $this->getInbox('DELETED'); + return $this->getInboxOverview('DELETED'); } - public function getInboxText(string $text) + /** + * Get all inbox messages with text. + * + * @param string $text Text in message body + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getInboxText(string $text) : array { - return $this->getInbox('TEXT "' . $text . '"'); + return $this->getInboxOverview('TEXT "' . $text . '"'); } public static function decode($content, $encoding) diff --git a/Message/Mail/Mail.php b/Message/Mail/Mail.php index c5b2aa891..4fe9b4e90 100644 --- a/Message/Mail/Mail.php +++ b/Message/Mail/Mail.php @@ -17,46 +17,232 @@ namespace phpOMS\Message\Mail; use phpOMS\Datatypes\Exception\InvalidEnumValue; -abstract class Mail +/** + * Mail class. + * + * @category Framework + * @package phpOMS\Message\Mail + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Mail { + /** + * Mail from. + * + * @var string + * @since 1.0.0 + */ protected $from = ''; + + /** + * Mail to. + * + * @var array + * @since 1.0.0 + */ protected $to = []; + + /** + * Mail subject. + * + * @var string + * @since 1.0.0 + */ protected $subject = ''; + + /** + * Mail cc. + * + * @var array + * @since 1.0.0 + */ protected $cc = []; + + /** + * Mail reply to. + * + * @var array + * @since 1.0.0 + */ protected $replyTo = []; + + /** + * Mail bcc. + * + * @var array + * @since 1.0.0 + */ protected $bcc = []; + + /** + * Mail attachments. + * + * @var array + * @since 1.0.0 + */ protected $attachment = []; + + /** + * Mail body. + * + * @var string + * @since 1.0.0 + */ protected $body = ''; + + /** + * Mail overview. + * + * @var string + * @since 1.0.0 + */ + protected $overview = ''; + + /** + * Mail alt. + * + * @var string + * @since 1.0.0 + */ protected $bodyAlt = ''; + + /** + * Mail mime. + * + * @var string + * @since 1.0.0 + */ protected $bodyMime = ''; + + /** + * Mail header. + * + * @var string + * @since 1.0.0 + */ protected $headerMail = ''; + + /** + * Word wrap. + * + * @var string + * @since 1.0.0 + */ protected $wordWrap = 78; + + /** + * Encoding. + * + * @var int + * @since 1.0.0 + */ + protected $encoding = 0; + + /** + * Mail type. + * + * @var int + * @since 1.0.0 + */ protected $type = MailType::MAIL; + + /** + * Mail host name. + * + * @var string + * @since 1.0.0 + */ protected $hostname = ''; + + /** + * Mail id. + * + * @var string + * @since 1.0.0 + */ protected $messageId = ''; + + /** + * Mail message type. + * + * @var string + * @since 1.0.0 + */ protected $messageType = ''; + + /** + * Mail from. + * + * @var \DateTime + * @since 1.0.0 + */ protected $messageDate = null; + /** + * todo: ??? + */ protected $mailer = null; - public function __construct(int $type) + /** + * Constructor. + * + * @param mixed $id Id + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct($id) { - $this->type = $type; + $this->messageId = $id; + } - switch ($type) { - case MailType::MAIL: - break; - case MailType::SMTP: - break; - case MailType::IMAP: - break; - case MailType::POP3: - break; - case MailType::SENDMAIL: - break; - default: - throw new InvalidEnumValue($type); - } + /** + * Set body. + * + * @param string $body Mail body + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setBody(string $body) + { + $this->body = $body; + } + + /** + * Set body. + * + * @param string $overview Mail overview + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setOverview(string $overview) + { + $this->overview = $overview; + } + + /** + * Set encoding. + * + * @param int $encoding Mail encoding + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setEncoding(int $encoding) + { + $this->encoding = $encoding; } } diff --git a/Message/Mail/MailType.php b/Message/Mail/MailType.php index a83779106..6478c25b2 100644 --- a/Message/Mail/MailType.php +++ b/Message/Mail/MailType.php @@ -21,7 +21,7 @@ use phpOMS\Datatypes\Enum; * Mail type. * * @category Framework - * @package phpOMS\DataStorage\Database + * @package phpOMS\Message\Mail * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 2195ee8a0..c80d2e817 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -325,6 +325,14 @@ abstract class RequestAbstract implements MessageInterface return $this->status; } + /** + * Get request header. + * + * @return HeaderAbstract + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getHeader() : HeaderAbstract { return $this->header; @@ -353,5 +361,13 @@ abstract class RequestAbstract implements MessageInterface */ abstract public function getRequestTarget() : string; + /** + * Get route verb. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ abstract public function getRouteVerb() : int; } diff --git a/Message/ResponseAbstract.php b/Message/ResponseAbstract.php index 67ad62e5f..9e63b8afe 100644 --- a/Message/ResponseAbstract.php +++ b/Message/ResponseAbstract.php @@ -186,5 +186,13 @@ abstract class ResponseAbstract implements MessageInterface return $this->header; } + /** + * Get response body. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ abstract public function getBody() : string; } diff --git a/Utils/Parser/Php/ClassParser.php b/Utils/Parser/Php/ClassParser.php index 9a07b3b2f..de483843c 100644 --- a/Utils/Parser/Php/ClassParser.php +++ b/Utils/Parser/Php/ClassParser.php @@ -16,9 +16,9 @@ namespace phpOMS\Utils\Parser\Php; /** - * Array parser class. + * Class parser class. * - * Parsing/serializing arrays to and from php file + * Parsing/serializing classes, interfaces to and from php file * * @category Framework * @package phpOMS\Utils\Parser @@ -30,38 +30,118 @@ namespace phpOMS\Utils\Parser\Php; */ class ClassParser { + /** + * Indention. + * + * @var int + * @since 1.0.0 + */ const INDENT = 4; + /** + * Is final? + * + * @var bool + * @since 1.0.0 + */ private $isFinal = false; + /** + * Is abstract? + * + * @var bool + * @since 1.0.0 + */ private $isAbstract = false; + /** + * Type. + * + * @var string + * @since 1.0.0 + */ private $type = ClassType::_CLASS; - private $extends = null; + /** + * Extends. + * + * @var string + * @since 1.0.0 + */ + private $extends = ''; - private $namespace = null; + /** + * Namespace. + * + * @var null|string + * @since 1.0.0 + */ + private $namespace = ''; + /** + * Includes. + * + * @var array + * @since 1.0.0 + */ private $includes = []; + /** + * Requires. + * + * @var array + * @since 1.0.0 + */ private $requires = []; + /** + * Uses. + * + * @var array + * @since 1.0.0 + */ private $use = []; + /** + * Name. + * + * @var string + * @since 1.0.0 + */ private $name = ''; + /** + * Implements. + * + * @var array + * @since 1.0.0 + */ private $implements = []; + /** + * Traits. + * + * @var array + * @since 1.0.0 + */ private $traits = []; + /** + * Members. + * + * @var MemberParser[] + * @since 1.0.0 + */ private $members = []; + /** + * Functions. + * + * @var FunctionParser[] + * @since 1.0.0 + */ private $functions = []; - public function __construct() - { - } - /** * Saving class to file. * @@ -74,68 +154,188 @@ class ClassParser */ public function createFile(string $path) { + // todo: implement } + /** + * Set final. + * + * @param bool $final Is final + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setFinal(bool $final) { $this->isFinal = $final; } + /** + * Is final? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isFinal() : bool { return $this->isFinal; } + /** + * Set abstract. + * + * @param bool $abstract Is abstract + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setAbstract(bool $abstract) { $this->isAbstract = $abstract; } + /** + * Is abstract? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isAbstract() : bool { return $this->isAbstract; } + /** + * Set type. + * + * Available types are ClassType:: + * + * @param string $type Set type + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setType(string $type) { $this->type = $type; } + /** + * Get type. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getType() : string { return $this->type; } + /** + * Set extends. + * + * @param string $extends Extended class + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setExtends(string $extends) { $this->extends = $extends; } + /** + * Get extends. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getExtends() : string { return $this->extends; } + /** + * Remove extends. + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeExtends() { - $this->extends = null; + $this->extends = ''; } + /** + * Set namespace. + * + * @param string $namespace Namespace + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setNamespace(string $namespace) { $this->namespace = $namespace; } + /** + * Get namespace. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getNamespace() : string { return $this->namespace; } + /** + * Remove namespace. + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeNamespace() { - $this->namespace = null; + $this->namespace = ''; } + /** + * Add use. + * + * @param string $namespace Namespace to use + * @param string $as Namespace as + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addUse(string $namespace, string $as = null) { if (isset($as)) { @@ -145,6 +345,16 @@ class ClassParser } } + /** + * Remove use. + * + * @param string $id Namespace numerical id or 'as' if used. + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeUse($id) : bool { if (isset($this->use[$id])) { @@ -156,16 +366,44 @@ class ClassParser return false; } + /** + * Set name. + * + * @param string $name Class name + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setName(string $name) { $this->name = $name; } + /** + * Get name. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getName() : string { return $this->name; } + /** + * Add implements. + * + * @param string $implements Implement + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addImplements(string $implements) { $this->implements[] = $implements; @@ -173,6 +411,16 @@ class ClassParser array_unique($this->implements); } + /** + * Add include. + * + * @param string $include Include + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addInclude(string $include) { $this->includes[] = $include; @@ -180,6 +428,16 @@ class ClassParser array_unique($this->includes); } + /** + * Add $require. + * + * @param string $require Require + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addRequire(string $require) { $this->requires[] = $require; @@ -187,6 +445,17 @@ class ClassParser array_unique($this->requires); } + /** + * Add trait. + * + * @param string $trait Trait to use + * @param string $as Trait as + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addTrait(string $trait, string $as = null) { if (isset($as)) { @@ -196,11 +465,52 @@ class ClassParser } } + /** + * Remove trait. + * + * @param string $id Namespace numerical id or 'as' if used. + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function removeTrait($id) : bool + { + if (isset($this->traits[$id])) { + unset($this->traits[$id]); + + return true; + } + + return false; + } + + /** + * Add member. + * + * @param MemberParser $member Member + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addMember(MemberParser $member) { $this->members[$member->getName()] = $member; } + /** + * Remove member by name. + * + * @param string $name Member name + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeMember(string $name) : bool { if (isset($this->members[$name])) { @@ -212,16 +522,46 @@ class ClassParser return false; } + /** + * Get member by name. + * + * @param string $name Member name + * + * @return MemberParser + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getMember(string $name) : MemberParser { return $this->members[$name] ?? new MemberParser(); } + /** + * Add function. + * + * @param FunctionParser $function Function + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function addFunction(FunctionParser $function) { $this->functions[$function->getName()] = $function; } + /** + * Remove function by name. + * + * @param string $name Function name + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeFunction(string $name) : bool { if (isset($this->functions[$name])) { @@ -233,12 +573,30 @@ class ClassParser return false; } + /** + * Get function by name. + * + * @param string $name Function name + * + * @return FunctionParser + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getFunction(string $name) : FunctionParser { return $this->functions[$name] ?? new FunctionParser(); } - public function parse() : string + /** + * Serialize class. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function serialize() : string { $class = ''; @@ -258,8 +616,8 @@ class ClassParser $class .= PHP_EOL; } - if (isset($namespace)) { - $class = $namespace . ';' . PHP_EOL . PHP_EOL; + if (!empty($this->namespace)) { + $class = $this->namespace . ';' . PHP_EOL . PHP_EOL; } if (!empty($this->use)) { @@ -280,7 +638,7 @@ class ClassParser $class .= $this->type . ' ' . $this->name . ' '; - if (isset($this->extends)) { + if (!empty($this->extends)) { $class .= 'extends ' . $this->extends . ' '; } @@ -299,11 +657,11 @@ class ClassParser } foreach ($this->members as $name => $member) { - $class .= $member->parse() . PHP_EOL . PHP_EOL; + $class .= $member->serialize() . PHP_EOL . PHP_EOL; } foreach ($this->functions as $name => $function) { - $class .= $function->parse() . PHP_EOL . PHP_EOL; + $class .= $function->serialize() . PHP_EOL . PHP_EOL; } $class .= '}'; diff --git a/Utils/Parser/Php/FunctionParser.php b/Utils/Parser/Php/FunctionParser.php index 2012022ea..3a50e58da 100644 --- a/Utils/Parser/Php/FunctionParser.php +++ b/Utils/Parser/Php/FunctionParser.php @@ -18,7 +18,7 @@ namespace phpOMS\Utils\Parser\Php; /** * Member parser class. * - * Parsing/serializing variables + * Parsing/serializing functions * * @category Framework * @package phpOMS\Utils\Parser diff --git a/Utils/Parser/Php/MemberParser.php b/Utils/Parser/Php/MemberParser.php index 20f7d5a7c..e5d254c25 100644 --- a/Utils/Parser/Php/MemberParser.php +++ b/Utils/Parser/Php/MemberParser.php @@ -18,7 +18,7 @@ namespace phpOMS\Utils\Parser\Php; /** * Member parser class. * - * Parsing/serializing variables + * Parsing/serializing member variables * * @category Framework * @package phpOMS\Utils\Parser @@ -30,36 +30,112 @@ namespace phpOMS\Utils\Parser\Php; */ class MemberParser { + /** + * Member name. + * + * @var string + * @since 1.0.0 + */ private $name = ''; + /** + * Member visibility. + * + * @var string + * @since 1.0.0 + */ private $visibility = Visibility::_PUBLIC; + /** + * Is static. + * + * @var bool + * @since 1.0.0 + */ private $isStatic = false; + /** + * Is const. + * + * @var bool + * @since 1.0.0 + */ private $isConst = false; + /** + * Default value. + * + * @var mixed + * @since 1.0.0 + */ private $default = null; + /** + * Set member name. + * + * @param string $name Member name + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setName(string $name) { $this->name = $name; } + /** + * Get member name. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getName() : string { return $this->name; } + /** + * Set visibility. + * + * @param string $visibility Member visibility + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setVisibility(string $visibility) { $this->visibility = $visibility; } + /** + * Get visibility. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getVisibility() : string { return $this->visibility; } + /** + * Set static. + * + * @param bool $static Is static + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setStatic(bool $static) { $this->isStatic = $static; @@ -69,11 +145,29 @@ class MemberParser } } + /** + * Is static? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isStatic() : bool { return $this->isStatic; } + /** + * Set const. + * + * @param bool $const Is const + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setConst(bool $const) { $this->isConst = $const; @@ -83,12 +177,43 @@ class MemberParser } } + /** + * Is const? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function isConst() : bool + { + return $this->isConst; + } + + /** + * Set default value. + * + * @param string $default + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setDefault($default) { $this->default = $default; } - public function parse() : string + /** + * Serialize member. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function serialize() : string { $member = ''; $member .= str_repeat(' ', ClassParser::INDENT); diff --git a/Utils/Parser/Php/Visibility.php b/Utils/Parser/Php/Visibility.php index 37be7f093..e32fc243c 100644 --- a/Utils/Parser/Php/Visibility.php +++ b/Utils/Parser/Php/Visibility.php @@ -18,9 +18,9 @@ namespace phpOMS\Utils\Parser\Php; use phpOMS\Datatypes\Enum; /** - * Database type enum. + * Visibility type enum. * - * Database types that are supported by the application + * Visibility for member variables and functions * * @category Framework * @package phpOMS\Utils\Parser @@ -32,6 +32,7 @@ use phpOMS\Datatypes\Enum; */ abstract class Visibility extends Enum { + const _NONE = ''; const _PUBLIC = 'public'; const _PRIVATE = 'private'; const _PROTECTED = 'protected'; diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index 64b446cb1..863fdd4a1 100644 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -26,47 +26,27 @@ namespace phpOMS\Utils\TaskSchedule; * @link http://orange-management.com * @since 1.0.0 */ -class Cron implements ScheduleInterface +class Cron extends SchedulerAbstract { - public function __construct() - { - - } - - public function add(TaskInterface $task) - { - // TODO: Implement add() method. - } - - public function remove($id) - { - // TODO: Implement remove() method. - } - - public function get(string $id) - { - // TODO: Implement get() method. - } - - public function list() - { - $output = shell_exec('crontab -l'); - - return $output; - } - - public function set(TaskInterface $task) - { - // TODO: Implement set() method. - } public function save() { } - public function run(string $cmd) + /** + * Run command + * + * @param string $cmd Command to run + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function run(string $cmd) : array { // TODO: Implement run() method. + return []; } } diff --git a/Utils/TaskSchedule/Schedule.php b/Utils/TaskSchedule/Schedule.php index 8dc669eb5..a14cf620d 100644 --- a/Utils/TaskSchedule/Schedule.php +++ b/Utils/TaskSchedule/Schedule.php @@ -28,8 +28,6 @@ namespace phpOMS\Utils\TaskSchedule; */ class Schedule extends TaskAbstract { - private $name = ''; - /** * Constructor. * diff --git a/Utils/TaskSchedule/ScheduleInterface.php b/Utils/TaskSchedule/ScheduleInterface.php deleted file mode 100644 index 98fed581a..000000000 --- a/Utils/TaskSchedule/ScheduleInterface.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @author Dennis Eichhorn - * @copyright 2013 Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 - * @link http://orange-management.com - */ -namespace phpOMS\Utils\TaskSchedule; - -/** - * Schedule Interface. - * - * @category Framework - * @package phpOMS\Utils\TaskSchedule - * @author OMS Development Team - * @author Dennis Eichhorn - * @license OMS License 1.0 - * @link http://orange-management.com - * @since 1.0.0 - */ -interface ScheduleInterface -{ - public function add(TaskInterface $task); - - public function remove($id); - - public function get(string $id); - - public function list(); - - public function set(TaskInterface $task); - - public function save(); - - public function run(string $cmd); -} diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php new file mode 100644 index 000000000..a49553ff8 --- /dev/null +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -0,0 +1,127 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Utils\TaskSchedule; + +/** + * Scheduler abstract. + * + * @category Framework + * @package phpOMS\Utils\TaskSchedule + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class SchedulerAbstract +{ + /** + * tasks. + * + * @var TaskAbstract[] + * @since 1.0.0 + */ + protected $tasks = []; + + /** + * Add task + * + * @param TaskAbstract $task Task to add + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function add(TaskAbstract $task) + { + $this->tasks[$task->getId()] = $task; + } + + /** + * Remove task + * + * @param mixed $id Task id + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function remove(string $id) : bool + { + if (isset($this->tasks[$id])) { + unset($this->tasks[$id]); + + return true; + } + + return false; + } + + /** + * Get task + * + * @param mixed $id Task id + * + * @return TaskAbstract|null + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function get(string $id) + { + return $this->tasks[$id] ?? null; + } + + /** + * Get all tasks + * + * @return TaskAbstract[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function list() : array + { + return $this->tasks; + } + + /** + * Set task + * + * @param TaskAbstract $task Task to edit + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function set(TaskAbstract $task) + { + $this->tasks[$task->getId()] = $task; + } + + /** + * Save tasks + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + abstract public function save(); +} diff --git a/Utils/TaskSchedule/TaskAbstract.php b/Utils/TaskSchedule/TaskAbstract.php index eb3e1641d..ccac3e21c 100644 --- a/Utils/TaskSchedule/TaskAbstract.php +++ b/Utils/TaskSchedule/TaskAbstract.php @@ -28,6 +28,14 @@ namespace phpOMS\Utils\TaskSchedule; */ abstract class TaskAbstract { + /** + * Id. + * + * @var string + * @since 1.0.0 + */ + protected $id = ''; + /** * Interval. * @@ -44,6 +52,19 @@ abstract class TaskAbstract */ protected $command = ''; + /** + * Get id. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : string + { + return $this->id; + } + /** * Set interval. * diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index 88bc34ee8..95ec74115 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -26,45 +26,27 @@ namespace phpOMS\Utils\TaskSchedule; * @link http://orange-management.com * @since 1.0.0 */ -class TaskScheduler implements ScheduleInterface +class TaskScheduler extends SchedulerAbstract { - public function __construct() - { - - } - - public function add(TaskInterface $task) - { - // TODO: Implement add() method. - } - - public function remove($id) - { - // TODO: Implement remove() method. - } - - public function get(string $id) - { - // TODO: Implement get() method. - } - - public function list() - { - // TODO: Implement list() method. - } - - public function set(TaskInterface $task) - { - // TODO: Implement set() method. - } public function save() { } - public function run(string $cmd) + /** + * Run command + * + * @param string $cmd Command to run + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function run(string $cmd) : array { // TODO: Implement run() method. + return []; } }