Skip to content

Commit

Permalink
Merge pull request #592 from phalcon/2.0.x
Browse files Browse the repository at this point in the history
2.0.12
  • Loading branch information
sergeyklay committed May 17, 2016
2 parents 8b77b9f + 46b6595 commit 3652e64
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
- TEST_DB_NAME="incubator_tests"
- TEST_DB_CHARSET="utf8"
matrix:
- PHALCON_VERSION="2.0.12"
- PHALCON_VERSION="2.0.11"
- PHALCON_VERSION="2.0.10"
- PHALCON_VERSION="2.0.9"
Expand Down
14 changes: 14 additions & 0 deletions Library/Phalcon/Db/Dialect/MysqlExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,26 @@ public function getSqlExpression(array $expression, $escapeChar = null, $bindCou
}

switch ($expression["arguments"][1]['value']) {
case "'MICROSECOND'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' MICROSECOND';
case "'SECOND'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' SECOND';
case "'MINUTE'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' MINUTE';
case "'HOUR'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' HOUR';
case "'DAY'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' DAY';
case "'WEEK'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' WEEK';
case "'MONTH'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' MONTH';
case "'QUARTER'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' QUARTER';
case "'YEAR'":
return 'INTERVAL ' . $this->getSqlExpression($expression["arguments"][0]) . ' YEAR';
default:
throw new \Exception('DATE_INTERVAL unit is not supported');
}
break;

Expand Down
183 changes: 183 additions & 0 deletions Library/Phalcon/Logger/Adapter/Udplogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Vitaliy Panait <[email protected]> |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Logger\Adapter;

use Phalcon\Logger\Exception;
use Phalcon\Logger\Formatter\Line as LineFormatter;
use Phalcon\Logger\Adapter as LoggerAdapter;
use Phalcon\Logger\AdapterInterface;

/**
* Phalcon\Logger\Adapter\Udplogger
* Sends messages using UDP protocol to external server
*
* @version 0.1
* @author Vitaliy Panait <[email protected]>
*/
class Udplogger extends LoggerAdapter implements AdapterInterface
{
/**
* Name
*
* @var string
*/
protected $name = 'phalcon';

/**
* Adapter options
*
* @var array
*/
protected $options = [];

/**
* @var resource
*/
protected $socket;

/**
* Storage for holding all messages until they are ready to be sent to server.
*
* @var array
*/
protected $logs = [];

/**
* Flag for the transaction
*
* @var boolean
*/
protected $isTransaction = false;

/**
* Class constructor.
*
* @param string $name
* @param array $options
* @throws \Phalcon\Logger\Exception
*/
public function __construct($name = 'phalcon', array $options = [])
{
if (!isset($options['url'])) {
throw new Exception("Parameter 'url' is required");
}

if (!isset($options['port'])) {
throw new Exception("Parameter 'port' is required");
}

if ($name) {
$this->name = $name;
}

$this->options = $options;

register_shutdown_function([$this, 'commit']);
register_shutdown_function([$this, 'close']);
}

/**
* {@inheritdoc}
*
* @return \Phalcon\Logger\FormatterInterface
*/
public function getFormatter()
{
if (!$this->_formatter) {
$this->_formatter = new LineFormatter();
}

return $this->_formatter;
}

/**
* Writes the log.
*
* @param string $message
* @param integer $type
* @param integer $time
* @param array $context
*/
public function logInternal($message, $type, $time, $context = [])
{
$this->logs[] = compact('message', 'type', 'time', 'context');

if (!$this->isTransaction) {
$this->send();
}
}

/**
* {@inheritdoc}
*
* @return boolean
*/
public function close()
{
if ($this->socket !== null) {
socket_close($this->socket);
}

return true;
}

/**
* {@inheritdoc}
*/
public function begin()
{
$this->commit();
$this->isTransaction = true;
}

/**
* {@inheritdoc}
*/
public function commit()
{
if (!$this->isTransaction || empty($this->logs)) {
$this->isTransaction = false;

return;
}

$this->send();
$this->isTransaction = false;
}

/**
* {@inheritdoc}
*/
protected function send()
{
if (empty($this->logs)) {
return;
}

$message = json_encode($this->logs);

if ($this->socket === null) {
$this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
}

socket_sendto($this->socket, $message, strlen($message), 0, $this->options['url'], $this->options['port']);

$this->logs = [];
}
}
18 changes: 18 additions & 0 deletions Library/Phalcon/Logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ $logger->info('Info Message');
// etc
```

## UDP logger

Adapter to send messages by UDP protocol to external server

```php
use Phalcon\Logger\Adapter\Udplogger as UdpLogger;

$di->set('logger', function() {

$logger = new UdpLogger('errors', [
'url' => $url,
'port' => $port
]);

return $logger;
});
```

## Multiple file logger

Adapter `Phalcon\Logger\Adapter\File\Multiple` can be used to log messages to multiple files. This is similar to the core
Expand Down
2 changes: 2 additions & 0 deletions Library/Phalcon/Mvc/Model/Behavior/NestedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,8 @@ private function addNode(ModelInterface $target, $key, $levelUp, array $attribut
private function makeRoot($attributes, $whiteList)
{
$owner = $this->getOwner();

$owner->{$this->rootAttribute} = 0;
$owner->{$this->leftAttribute} = 1;
$owner->{$this->rightAttribute} = 2;
$owner->{$this->levelAttribute} = 1;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ See [CONTRIBUTING.md](docs/CONTRIBUTING.md)
### Logger
* [Phalcon\Logger\Adapter\Database](Library/Phalcon/Logger) - Adapter to store logs in a database table (!phalcon)
* [Phalcon\Logger\Adapter\Firelogger](Library/Phalcon/Logger) - Adapter to log messages in the Firelogger console in Firebug (@phalcon)
* [Phalcon\Logger\Adapter\Udplogger](Library/Phalcon/Logger) - Adapter to log messages using UDP protocol to external server (@vitalypanait)
* [Phalcon\Logger\Adapter\File\Multiple](Library/Phalcon/Logger) - Adapter to log to multiple files (@rlaffers)

### Mailer
Expand Down

0 comments on commit 3652e64

Please sign in to comment.