Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed May 1, 2018
2 parents 3841b0a + ab383b5 commit 6d95e93
Show file tree
Hide file tree
Showing 31 changed files with 976 additions and 121 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,3 +1,4 @@
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
tests/ export-ignore
9 changes: 8 additions & 1 deletion .travis.yml
Expand Up @@ -4,16 +4,23 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

script:
- vendor/bin/tester tests -j 1 -s -p php -c tests/php-unix.ini
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
- if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then php temp/code-checker/src/code-checker.php; fi

after_failure:
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

before_script:
- travis_retry composer install --no-interaction
- if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then travis_retry composer create-project nette/code-checker temp/code-checker ~2; fi
# Modify code-checker tasks
- if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then sed -i -e 's/tabIndentationPhpChecker/yamlIndentationChecker/g' temp/code-checker/src/bootstrap.php; fi
- if [ "$TRAVIS_PHP_VERSION" = "7.2" ]; then sed -i -e 's/\*\.css,\*\.less,\*\.js,\*\.json,\*\.neon/\*\.css,\*\.less,\*\.js,\*\.json/g' temp/code-checker/src/bootstrap.php; fi

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,6 +1,6 @@
{
"name": "tharos/leanmapper",
"description": "Tiny ORM based on powerful dibi database abstraction library for PHP 5.",
"description": "Tiny ORM based on powerful dibi database abstraction library for PHP.",
"homepage": "http://www.leanmapper.com",
"license": "MIT",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion license.md
Expand Up @@ -19,4 +19,4 @@ 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.
OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -5,7 +5,7 @@ Lean Mapper

[![Build Status](https://travis-ci.org/Tharos/LeanMapper.svg?branch=develop)](https://travis-ci.org/Tharos/LeanMapper)

Lean Mapper is a tiny ORM based on powerful [dibi database abstraction library](http://dibiphp.com) for PHP 5.
Lean Mapper is a tiny ORM based on powerful [dibi database abstraction library](http://dibiphp.com) for PHP.

See [www.leanmapper.com](http://www.leanmapper.com) for more informations, usage examples and documentation.

Expand Down
8 changes: 4 additions & 4 deletions src/LeanMapper/DefaultEntityFactory.php
Expand Up @@ -19,8 +19,8 @@
class DefaultEntityFactory implements IEntityFactory
{

/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function createEntity($entityClass, $arg = null)
{
Expand All @@ -29,8 +29,8 @@ public function createEntity($entityClass, $arg = null)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function createCollection(array $entities)
{
Expand Down
36 changes: 18 additions & 18 deletions src/LeanMapper/DefaultMapper.php
Expand Up @@ -29,8 +29,8 @@ class DefaultMapper implements IMapper



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getPrimaryKey($table)
{
Expand All @@ -39,8 +39,8 @@ public function getPrimaryKey($table)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getTable($entityClass)
{
Expand All @@ -49,8 +49,8 @@ public function getTable($entityClass)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getEntityClass($table, Row $row = null)
{
Expand All @@ -59,8 +59,8 @@ public function getEntityClass($table, Row $row = null)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getColumn($entityClass, $field)
{
Expand All @@ -69,8 +69,8 @@ public function getColumn($entityClass, $field)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getEntityField($table, $column)
{
Expand All @@ -79,8 +79,8 @@ public function getEntityField($table, $column)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getRelationshipTable($sourceTable, $targetTable)
{
Expand All @@ -89,8 +89,8 @@ public function getRelationshipTable($sourceTable, $targetTable)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getRelationshipColumn($sourceTable, $targetTable)
{
Expand All @@ -99,8 +99,8 @@ public function getRelationshipColumn($sourceTable, $targetTable)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getTableByRepositoryClass($repositoryClass)
{
Expand All @@ -113,8 +113,8 @@ public function getTableByRepositoryClass($repositoryClass)



/*
* @inheritdoc
/**
* {@inheritdoc}
*/
public function getImplicitFilters($entityClass, Caller $caller = null)
{
Expand Down
5 changes: 2 additions & 3 deletions src/LeanMapper/Entity.php
Expand Up @@ -673,11 +673,10 @@ protected function set($property, $value)
if ($property->isBasicType()) {
if ($pass !== null) {
$value = $this->$pass($value);
}
if ($value !== null) {
} elseif ($value !== null) {
settype($value, $property->getType());
}
if ($property->containsEnumeration() and !$property->isValueFromEnum($value)) {
if ($value !== null and $property->containsEnumeration() and !$property->isValueFromEnum($value)) {
throw new InvalidValueException(
"Given value is not from possible values enumeration in property '{$property->getName()}' in entity " . get_called_class() . '.'
);
Expand Down
14 changes: 7 additions & 7 deletions src/LeanMapper/Fluent.php
Expand Up @@ -24,13 +24,13 @@ class Fluent extends \Dibi\Fluent

/** @var array */
public static $masks = [ // fixes missing UNION in dibi
'SELECT' => [
'SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', 'UNION',
],
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
'SELECT' => [
'SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', 'UNION',
],
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
];

/** @var array */
Expand Down
8 changes: 7 additions & 1 deletion src/LeanMapper/Reflection/EntityReflection.php
Expand Up @@ -179,6 +179,12 @@ private function parseProperties()
foreach (AnnotationsParser::parseAnnotationValues($annotationType, $member->getDocComment()) as $definition) {
$property = PropertyFactory::createFromAnnotation($annotationType, $definition, $member, $this->mapper);
// collision check
if (isset($this->properties[$property->getName()])) {
throw new InvalidStateException(
"Duplicated property '{$property->getName()}' in entity {$this->getName()}. Please fix property name."
);
}

$column = $property->getColumn();
if ($column !== null and $property->isWritable()) {
if (isset($columns[$column])) {
Expand All @@ -199,7 +205,7 @@ private function parseProperties()
private function initGettersAndSetters()
{
$this->getters = $this->setters = [];
foreach ($this->getMethods() as $method) {
foreach ($this->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$name = $method->getName();
if (strlen($name) > 3) {
$prefix = substr($name, 0, 3);
Expand Down
80 changes: 40 additions & 40 deletions src/LeanMapper/Reflection/PropertyFactory.php
Expand Up @@ -50,19 +50,19 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
$matches = [];
$matched = preg_match(
'~
^(null\|)?
((?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+)
(\[\])?
(\|null)?\s+
(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)
(?:\s+=\s*(?:
"((?:\\\\"|[^"])+)" | # double quoted string
\'((?:\\\\\'|[^\'])+)\' | # single quoted string
([^ ]*)) # unquoted value
)?
(?:\s*\(([^)]+)\))?
(?:\s+(.*)\s*)?
~xi',
^(null\|)?
((?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+)
(\[\])?
(\|null)?\s+
(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)
(?:\s+=\s*(?:
"((?:\\\\"|[^"])+)" | # double quoted string
\'((?:\\\\\'|[^\'])+)\' | # single quoted string
([^ ]*)) # unquoted value
)?
(?:\s*\(([^)]+)\))?
(?:\s+(.*)\s*)?
~xi',
$annotation,
$matches
);
Expand Down Expand Up @@ -93,18 +93,6 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
} elseif (isset($matches[8]) and $matches[8] !== '') {
$defaultValue = $matches[8];
}
if ($defaultValue !== null) {
$hasDefaultValue = true;
try {
$defaultValue = self::fixDefaultValue($defaultValue, $propertyType, $isNullable);
} catch (InvalidAnnotationException $e) {
throw new InvalidAnnotationException(
"Invalid property definition given: @$annotationType $annotation in entity {$entityReflection->getName()}, " . lcfirst(
$e->getMessage()
)
);
}
}
$column = $mapper !== null ? $mapper->getColumn($entityReflection->getName(), $name) : $name;
if (isset($matches[9]) and $matches[9] !== '') {
$column = $matches[9];
Expand All @@ -117,14 +105,12 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
$propertyValuesEnum = null;
$customFlags = [];
$customColumn = null;
$customDefault = null;

if (isset($matches[10])) {
$flagMatches = [];
preg_match_all('~m:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*(?:\(([^)]*)\))?~', $matches[10], $flagMatches, PREG_SET_ORDER);
preg_match_all('~m:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff-]*)\s*(\(((?>[^)(]+|(?2))*)\))?~', $matches[10], $flagMatches, PREG_SET_ORDER);
foreach ($flagMatches as $match) {
$flag = $match[1];
$flagArgument = (isset($match[2]) and $match[2] !== '') ? $match[2] : null;
$flagArgument = (isset($match[3]) and $match[3] !== '') ? $match[3] : null;

switch ($flag) {
case 'hasOne':
Expand Down Expand Up @@ -200,7 +186,7 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
$customColumn = $flagArgument;
break;
case 'default':
if ($customDefault !== null) {
if ($defaultValue !== null) {
throw new InvalidAnnotationException(
"Multiple default value settings found in property definition: @$annotationType $annotation in entity {$entityReflection->getName()}."
);
Expand All @@ -212,25 +198,26 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
}
$matched = preg_match(
'~
^\s*(?:
"((?:\\\\"|[^"])+)" | # double quoted string
\'((?:\\\\\'|[^\'])+)\' | # single quoted string
([^ ]*) # unquoted value
)
~xi',
^\s*(?:
"((?:\\\\"|[^"])+)" | # double quoted string
\'((?:\\\\\'|[^\'])+)\' | # single quoted string
([^ ]*) # unquoted value
)
~xi',
$flagArgument,
$matches
);
if (!$matched) {
throw new \Exception;
}
if (isset($matches[1]) and $matches[1] !== '') {
$customDefault = str_replace('\"', '"', $matches[1]);
$defaultValue = str_replace('\"', '"', $matches[1]);
} elseif (isset($matches[2]) and $matches[2] !== '') {
$customDefault = str_replace("\\'", "'", $matches[2]);
$defaultValue = str_replace("\\'", "'", $matches[2]);
} elseif (isset($matches[3]) and $matches[3] !== '') {
$customDefault = $matches[3];
$defaultValue = $matches[3];
}

break;
default:
if (array_key_exists($flag, $customFlags)) {
Expand All @@ -243,8 +230,21 @@ public static function createFromAnnotation($annotationType, $annotation, Entity
}
}

if ($defaultValue !== null) {
$hasDefaultValue = true;

try {
$defaultValue = self::fixDefaultValue($defaultValue, $propertyType, $isNullable);
} catch (InvalidAnnotationException $e) {
throw new InvalidAnnotationException(
"Invalid property definition given: @$annotationType $annotation in entity {$entityReflection->getName()}, " . lcfirst(
$e->getMessage()
)
);
}
}

$column = $customColumn ?: $column;
$defaultValue = $customDefault ?: $defaultValue;

return new Property(
$name,
Expand Down
5 changes: 3 additions & 2 deletions src/LeanMapper/Reflection/PropertyValuesEnum.php
Expand Up @@ -39,14 +39,15 @@ public function __construct($definition, EntityReflection $reflection)
{
$matches = [];
preg_match(
'#^((?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+|self|static|parent)::([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)\*$#',
'#^((?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+|self|static|parent)::([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)?\*$#',
$definition,
$matches
);
if (empty($matches)) {
throw new InvalidAnnotationException("Invalid enumeration definition given: '$definition'.");
}
list(, $class, $prefix) = $matches;
$class = $matches[1];
$prefix = array_key_exists(2, $matches) ? $matches[2] : '';

if ($class === 'self' or $class === 'static') {
$constants = $reflection->getConstants();
Expand Down

0 comments on commit 6d95e93

Please sign in to comment.