Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend

This commit is contained in:
Yuri Kuznetsov
2013-12-23 17:24:41 +02:00
11 changed files with 845 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
# How to Contribute
## Pull Requests
1. Fork the Slim Framework repository
2. Create a new branch for each feature or improvement
3. Send a pull request from each feature branch to the **develop** branch
It is very important to separate new features or improvements into separate feature branches, and to send a
pull request for each branch. This allows me to review and pull in new features or improvements individually.
## Style Guide
All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
## Unit Testing
All pull requests must be accompanied by passing unit tests and complete code coverage. The Slim Framework uses phpunit for testing.
[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/)
+246
View File
@@ -0,0 +1,246 @@
<?php
/**
* Slim - a micro PHP 5 framework
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.0
* @package Slim
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Slim\Helper;
class Set implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* Key-value array of arbitrary data
* @var array
*/
protected $data = array();
/**
* Constructor
* @param array $items Pre-populate set with this key-value array
*/
public function __construct($items = array())
{
$this->replace($items);
}
/**
* Normalize data key
*
* Used to transform data key into the necessary
* key format for this set. Used in subclasses
* like \Slim\Http\Headers.
*
* @param string $key The data key
* @return mixed The transformed/normalized data key
*/
protected function normalizeKey($key)
{
return $key;
}
/**
* Set data key to value
* @param string $key The data key
* @param mixed $value The data value
*/
public function set($key, $value)
{
$this->data[$this->normalizeKey($key)] = $value;
}
/**
* Get data value with key
* @param string $key The data key
* @param mixed $default The value to return if data key does not exist
* @return mixed The data value, or the default value
*/
public function get($key, $default = null)
{
if ($this->has($key)) {
$isInvokable = is_object($this->data[$this->normalizeKey($key)]) && method_exists($this->data[$this->normalizeKey($key)], '__invoke');
return $isInvokable ? $this->data[$this->normalizeKey($key)]($this) : $this->data[$this->normalizeKey($key)];
}
return $default;
}
/**
* Add data to set
* @param array $items Key-value array of data to append to this set
*/
public function replace($items)
{
foreach ($items as $key => $value) {
$this->set($key, $value); // Ensure keys are normalized
}
}
/**
* Fetch set data
* @return array This set's key-value data array
*/
public function all()
{
return $this->data;
}
/**
* Fetch set data keys
* @return array This set's key-value data array keys
*/
public function keys()
{
return array_keys($this->data);
}
/**
* Does this set contain a key?
* @param string $key The data key
* @return boolean
*/
public function has($key)
{
return array_key_exists($this->normalizeKey($key), $this->data);
}
/**
* Remove value with key from this set
* @param string $key The data key
*/
public function remove($key)
{
unset($this->data[$this->normalizeKey($key)]);
}
/**
* Property Overloading
*/
public function __get($key)
{
return $this->get($key);
}
public function __set($key, $value)
{
$this->set($key, $value);
}
public function __isset($key)
{
return $this->has($key);
}
public function __unset($key)
{
return $this->remove($key);
}
/**
* Clear all values
*/
public function clear()
{
$this->data = array();
}
/**
* Array Access
*/
public function offsetExists($offset)
{
return $this->has($offset);
}
public function offsetGet($offset)
{
return $this->get($offset);
}
public function offsetSet($offset, $value)
{
$this->set($offset, $value);
}
public function offsetUnset($offset)
{
$this->remove($offset);
}
/**
* Countable
*/
public function count()
{
return count($this->data);
}
/**
* IteratorAggregate
*/
public function getIterator()
{
return new \ArrayIterator($this->data);
}
/**
* Ensure a value or object will remain globally unique
* @param string $key The value or object name
* @param Closure The closure that defines the object
* @return mixed
*/
public function singleton($key, $value)
{
$this->set($key, function ($c) use ($value) {
static $object;
if (null === $object) {
$object = $value($c);
}
return $object;
});
}
/**
* Protect closure from being directly invoked
* @param Closure $callable A closure to keep from being invoked and evaluated
* @return Closure
*/
public function protect(\Closure $callable)
{
return function () use ($callable) {
return $callable;
};
}
}
+91
View File
@@ -0,0 +1,91 @@
<?php
/**
* Slim - a micro PHP 5 framework
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.0
* @package Slim
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Slim\Http;
class Cookies extends \Slim\Helper\Set
{
/**
* Default cookie settings
* @var array
*/
protected $defaults = array(
'value' => '',
'domain' => null,
'path' => null,
'expires' => null,
'secure' => false,
'httponly' => false
);
/**
* Set cookie
*
* The second argument may be a single scalar value, in which case
* it will be merged with the default settings and considered the `value`
* of the merged result.
*
* The second argument may also be an array containing any or all of
* the keys shown in the default settings above. This array will be
* merged with the defaults shown above.
*
* @param string $key Cookie name
* @param mixed $value Cookie settings
*/
public function set($key, $value)
{
if (is_array($value)) {
$cookieSettings = array_replace($this->defaults, $value);
} else {
$cookieSettings = array_replace($this->defaults, array('value' => $value));
}
parent::set($key, $cookieSettings);
}
/**
* Remove cookie
*
* Unlike \Slim\Helper\Set, this will actually *set* a cookie with
* an expiration date in the past. This expiration date will force
* the client-side cache to remove its cookie with the given name
* and settings.
*
* @param string $key Cookie name
* @param array $settings Optional cookie settings
*/
public function remove($key, $settings = array())
{
$settings['value'] = '';
$settings['expires'] = time() - 86400;
$this->set($key, array_replace($this->defaults, $settings));
}
}
+241
View File
@@ -0,0 +1,241 @@
<?php
/**
* Slim - a micro PHP 5 framework
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.0
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
class SetTest extends PHPUnit_Framework_TestCase
{
protected $bag;
protected $property;
public function setUp()
{
$this->bag = new \Slim\Helper\Set();
$this->property = new \ReflectionProperty($this->bag, 'data');
$this->property->setAccessible(true);
}
public function testSet()
{
$this->bag->set('foo', 'bar');
$this->assertArrayHasKey('foo', $this->property->getValue($this->bag));
$bag = $this->property->getValue($this->bag);
$this->assertEquals('bar', $bag['foo']);
}
public function testGet()
{
$this->property->setValue($this->bag, array('foo' => 'bar'));
$this->assertEquals('bar', $this->bag->get('foo'));
}
public function testGetNotExists()
{
$this->property->setValue($this->bag, array('foo' => 'bar'));
$this->assertEquals('default', $this->bag->get('abc', 'default'));
}
public function testAdd()
{
$this->bag->replace(array(
'abc' => '123',
'foo' => 'bar'
));
$this->assertArrayHasKey('abc', $this->property->getValue($this->bag));
$this->assertArrayHasKey('foo', $this->property->getValue($this->bag));
$bag = $this->property->getValue($this->bag);
$this->assertEquals('123', $bag['abc']);
$this->assertEquals('bar', $bag['foo']);
}
public function testAll()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertEquals($data, $this->bag->all());
}
public function testKeys()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertEquals(array('abc', 'foo'), $this->bag->keys());
}
public function testRemove()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->bag->remove('foo');
$this->assertEquals(array('abc' => '123'), $this->property->getValue($this->bag));
}
public function testClear()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->bag->clear();
$this->assertEquals(array(), $this->property->getValue($this->bag));
}
public function testArrayAccessGet()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertEquals('bar', $this->bag['foo']);
}
public function testArrayAccessSet()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->bag['foo'] = 'changed';
$bag = $this->property->getValue($this->bag);
$this->assertEquals('changed', $bag['foo']);
}
public function testArrayAccessExists()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertTrue(isset($this->bag['foo']));
$this->assertFalse(isset($this->bag['bar']));
}
public function testArrayAccessUnset()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
unset($this->bag['foo']);
$this->assertEquals(array('abc' => '123'), $this->property->getValue($this->bag));
}
public function testCount()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertEquals(2, count($this->bag));
}
public function testGetIterator()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertInstanceOf('\ArrayIterator', $this->bag->getIterator());
}
public function testPropertyOverloadGet()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertEquals('123', $this->bag->abc);
$this->assertEquals('bar', $this->bag->foo);
}
public function testPropertyOverloadSet()
{
$this->bag->foo = 'bar';
$this->assertArrayHasKey('foo', $this->property->getValue($this->bag));
$this->assertEquals('bar', $this->bag->foo);
}
public function testPropertyOverloadingIsset()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertTrue(isset($this->bag->abc));
$this->assertTrue(isset($this->bag->foo));
$this->assertFalse(isset($this->bag->foobar));
}
public function testPropertyOverloadingUnset()
{
$data = array(
'abc' => '123',
'foo' => 'bar'
);
$this->property->setValue($this->bag, $data);
$this->assertTrue(isset($this->bag->abc));
unset($this->bag->abc);
$this->assertFalse(isset($this->bag->abc));
$this->assertArrayNotHasKey('abc', $this->property->getValue($this->bag));
$this->assertArrayHasKey('foo', $this->property->getValue($this->bag));
}
public function testProtect()
{
$callable = function () {
return 'foo';
};
$result = $this->bag->protect($callable);
$this->assertInstanceOf('\Closure', $result);
$this->assertSame($callable, $result());
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
/**
* Slim - a micro PHP 5 framework
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.0
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
class CookiesTest extends PHPUnit_Framework_TestCase
{
public function testSetWithStringValue()
{
$c = new \Slim\Http\Cookies();
$c->set('foo', 'bar');
$this->assertAttributeEquals(
array(
'foo' => array(
'value' => 'bar',
'expires' => null,
'domain' => null,
'path' => null,
'secure' => false,
'httponly' => false
)
),
'data',
$c
);
}
public function testSetWithArrayValue()
{
$now = time();
$c = new \Slim\Http\Cookies();
$c->set('foo', array(
'value' => 'bar',
'expires' => $now + 86400,
'domain' => '.example.com',
'path' => '/',
'secure' => true,
'httponly' => true
));
$this->assertAttributeEquals(
array(
'foo' => array(
'value' => 'bar',
'expires' => $now + 86400,
'domain' => '.example.com',
'path' => '/',
'secure' => true,
'httponly' => true
)
),
'data',
$c
);
}
public function testRemove()
{
$c = new \Slim\Http\Cookies();
$c->remove('foo');
$prop = new \ReflectionProperty($c, 'data');
$prop->setAccessible(true);
$cValue = $prop->getValue($c);
$this->assertEquals('', $cValue['foo']['value']);
$this->assertLessThan(time(), $cValue['foo']['expires']);
}
}
@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputAwareInterface;
/**
* An implementation of InputAwareInterface for Helpers.
*
* @author Wouter J <waldio.webdesign@gmail.com>
*/
abstract class InputAwareHelper extends Helper implements InputAwareInterface
{
protected $input;
/**
* {@inheritDoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
}
}
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Input;
/**
* InputAwareInterface should be implemented by classes that depends on the
* Console Input.
*
* @author Wouter J <waldio.webdesign@gmail.com>
*/
interface InputAwareInterface
{
/**
* Sets the Console Input.
*
* @param InputInterface
*/
public function setInput(InputInterface $input);
}
@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Output;
/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class BufferedOutput extends Output
{
/**
* @var string
*/
private $buffer = '';
/**
* Empties buffer and returns its content.
*
* @return string
*/
public function fetch()
{
$content = $this->buffer;
$this->buffer = '';
return $content;
}
/**
* {@inheritdoc}
*/
protected function doWrite($message, $newline)
{
$this->buffer .= $message;
if ($newline) {
$this->buffer .= "\n";
}
}
}
@@ -0,0 +1,11 @@
<?php
use Symfony\Component\Console\Command\Command;
class BarBucCommand extends Command
{
protected function configure()
{
$this->setName('bar:buc');
}
}
@@ -0,0 +1,10 @@
<?php
use Symfony\Component\Console\Command\Command;
class Foo5Command extends Command
{
public function __construct()
{
}
}
@@ -0,0 +1,25 @@
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class FoobarCommand extends Command
{
public $input;
public $output;
protected function configure()
{
$this
->setName('foobar:foo')
->setDescription('The foobar:foo command')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
}
}