Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LeanMapper Workflow
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Mpro
LeanMapper Workflow
Commits
e9c054c2
Commit
e9c054c2
authored
Jun 04, 2014
by
Tomas Lang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix coding style
parent
36857561
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
64 deletions
+63
-64
AbstractRepository.php
src/LeanMapperWorkflow/AbstractRepository.php
+11
-10
AbstractRestriction.php
src/LeanMapperWorkflow/AbstractRestriction.php
+27
-26
Entity.php
src/LeanMapperWorkflow/Entity.php
+3
-7
Mapper.php
src/LeanMapperWorkflow/Mapper.php
+8
-13
Repository.php
src/LeanMapperWorkflow/Repository.php
+1
-0
Restriction.php
src/LeanMapperWorkflow/Restriction.php
+7
-3
FindEntity.php
src/LeanMapperWorkflow/Traits/FindEntity.php
+6
-5
No files found.
src/LeanMapperWorkflow/AbstractRepository.php
View file @
e9c054c2
...
...
@@ -2,17 +2,12 @@
namespace
LeanMapperWorkflow
;
use
InvalidArgumentException
;
abstract
class
AbstractRepository
extends
\LeanMapper\Repository
{
/**
* @return Restriction
*/
abstract
public
function
createRestriction
();
/**
* @param \DibiFluent $statement
* @param Restriction|null $restriction
...
...
@@ -26,12 +21,18 @@ abstract class AbstractRepository extends \LeanMapper\Repository
$restriction
=
$this
->
createRestriction
();
}
if
(
$restriction
instanceof
Restriction
)
{
if
(
$restriction
instanceof
Restriction
)
{
$restriction
->
apply
(
$statement
,
$this
,
$flag
);
}
else
{
throw
new
\
InvalidArgumentException
(
'Parameter "restriction" ('
.
get_class
(
$restriction
)
.
') must be instance of '
.
__NAMESPACE__
.
'\\Restriction.'
);
throw
new
InvalidArgumentException
(
'Parameter "restriction" ('
.
get_class
(
$restriction
)
.
') must be instance of '
.
__NAMESPACE__
.
'\\Restriction.'
);
}
}
/**
* @return Restriction
*/
abstract
public
function
createRestriction
();
}
src/LeanMapperWorkflow/AbstractRestriction.php
View file @
e9c054c2
...
...
@@ -30,19 +30,22 @@ abstract class AbstractRestriction
$element
=
new
\Nette\Reflection\ClassType
(
get_class
(
$this
));
do
{
do
{
$annotations
=
$element
->
getAnnotations
(
'property'
);
if
(
isset
(
$annotations
[
'property'
]))
foreach
(
$annotations
[
'property'
]
as
$property
)
if
((
$parsedProperty
=
$this
->
parseProperty
(
$property
))
!==
NULL
&&
!
isset
(
$this
->
properties
[
$parsedProperty
[
'variable'
]]))
if
(
isset
(
$annotations
[
'property'
]))
{
foreach
(
$annotations
[
'property'
]
as
$property
)
{
if
((
$parsedProperty
=
$this
->
parseProperty
(
$property
))
!==
NULL
&&
!
isset
(
$this
->
properties
[
$parsedProperty
[
'variable'
]]))
{
$this
->
properties
[
$parsedProperty
[
'variable'
]]
=
$parsedProperty
[
'type'
];
}
}
}
if
(
$element
instanceof
\Nette\Reflection\ClassType
)
if
(
$element
instanceof
\Nette\Reflection\ClassType
)
{
$element
=
$element
->
getParentClass
();
else
}
else
{
$element
=
NULL
;
}
}
while
(
$element
!==
NULL
);
$this
->
initDefaults
();
...
...
@@ -105,35 +108,32 @@ abstract class AbstractRestriction
*/
public
function
__set
(
$key
,
$value
)
{
if
(
!
isset
(
$this
->
properties
[
$key
]))
if
(
!
isset
(
$this
->
properties
[
$key
]))
{
throw
new
\InvalidArgumentException
(
"'
{
$key
}
' is not defined."
);
}
$types
=
$this
->
properties
[
$key
];
if
(
is_object
(
$value
))
{
if
(
is_object
(
$value
))
{
$found
=
FALSE
;
foreach
(
$types
as
$class
)
if
(
class_exists
(
$class
)
&&
$value
instanceof
$class
)
foreach
(
$types
as
$class
)
{
if
(
class_exists
(
$class
)
&&
$value
instanceof
$class
)
{
$found
=
TRUE
;
}
}
if
(
!
$found
)
if
(
!
$found
)
{
throw
new
\InvalidArgumentException
(
'Unexpected class.'
);
}
elseif
(
is_array
(
$value
)
&&
in_array
(
'array'
,
$types
))
{
}
elseif
(
$value
===
NULL
&&
in_array
(
'null'
,
$types
))
{
}
elseif
(
in_array
(
'int'
,
$types
)
&&
is_numeric
(
$value
))
{
}
}
elseif
(
is_array
(
$value
)
&&
in_array
(
'array'
,
$types
))
{
}
elseif
(
$value
===
NULL
&&
in_array
(
'null'
,
$types
))
{
}
elseif
(
in_array
(
'int'
,
$types
)
&&
is_numeric
(
$value
))
{
$value
=
(
int
)
$value
;
}
elseif
(
in_array
(
'bool'
,
$types
)
||
in_array
(
'boolean'
,
$types
))
{
}
elseif
(
in_array
(
'bool'
,
$types
)
||
in_array
(
'boolean'
,
$types
))
{
$value
=
(
bool
)
$value
;
}
elseif
(
in_array
(
'string'
,
$types
))
{
}
elseif
(
in_array
(
'string'
,
$types
))
{
$value
=
(
string
)
$value
;
}
else
{
}
else
{
throw
new
\InvalidArgumentException
(
'Unexpected value.'
);
}
...
...
@@ -151,8 +151,9 @@ abstract class AbstractRestriction
*/
public
function
&
__get
(
$key
)
{
if
(
!
array_key_exists
(
$key
,
$this
->
values
))
if
(
!
array_key_exists
(
$key
,
$this
->
values
))
{
throw
new
\InvalidArgumentException
(
"'
{
$key
}
' is not filled or defined."
);
}
return
$this
->
values
[
$key
];
}
...
...
src/LeanMapperWorkflow/Entity.php
View file @
e9c054c2
...
...
@@ -6,7 +6,6 @@ use LeanMapper\Relationship\HasMany;
use
LeanMapper\Filtering
;
use
LeanMapper\Fluent
;
use
InvalidArgumentException
;
use
Nette\Callback
;
use
Nette\Utils\Strings
;
...
...
@@ -21,19 +20,16 @@ abstract class Entity extends \LeanMapper\Entity
*/
public
function
__call
(
$name
,
array
$arguments
)
{
if
(
in_array
(
$name
,
[
'addTo'
,
'removeFrom'
,
'removeAll'
,
'replaceAll'
,
'getCountOf'
]))
{
if
(
in_array
(
$name
,
[
'addTo'
,
'removeFrom'
,
'removeAll'
,
'replaceAll'
,
'getCountOf'
]))
{
if
(
count
(
$arguments
)
===
0
)
{
throw
new
InvalidArgumentException
(
"Method '
$name
' in entity "
.
get_called_class
()
.
" expects at least one argument with target column name."
);
}
return
$this
->
__call
(
$name
.
Strings
::
firstUpper
(
array_shift
(
$arguments
)),
$arguments
);
}
elseif
(
substr
(
$name
,
0
,
10
)
===
'getCountOf'
)
{
}
elseif
(
substr
(
$name
,
0
,
10
)
===
'getCountOf'
)
{
$property
=
$this
->
getCurrentReflection
()
->
getEntityProperty
(
lcfirst
(
substr
(
$name
,
10
)));
if
(
$property
->
containsCollection
())
{
if
(
$property
->
containsCollection
())
{
$relationship
=
$property
->
getRelationship
();
$table
=
$relationship
instanceof
HasMany
?
$relationship
->
getRelationshipTable
()
:
$relationship
->
getTargetTable
();
$column
=
$relationship
->
getColumnReferencingSourceTable
();
...
...
src/LeanMapperWorkflow/Mapper.php
View file @
e9c054c2
...
...
@@ -3,16 +3,9 @@
namespace
LeanMapperWorkflow
;
/**
* Class Mapper
*/
class
Mapper
extends
\LeanMapper\DefaultMapper
{
const
STANDARD_NAMESPACE
=
'App\\Model'
;
/** @var array */
protected
$mapping
;
...
...
@@ -73,12 +66,13 @@ class Mapper extends \LeanMapper\DefaultMapper
*/
public
function
getNamespaceFromTable
(
$tableName
)
{
if
(
empty
(
$tableName
))
if
(
empty
(
$tableName
))
{
throw
new
\InvalidArgumentException
(
'Method getNamespaceFromTable received invalid (empty) parameter.'
);
}
if
(
isset
(
$this
->
tableMapping
[
$tableName
]))
if
(
isset
(
$this
->
tableMapping
[
$tableName
]))
{
return
$this
->
tableMapping
[
$tableName
];
else
{
}
else
{
return
$this
->
baseNamespace
.
'\\'
.
implode
(
'\\'
,
array_map
(
'ucfirst'
,
explode
(
'_'
,
$tableName
)));
}
}
...
...
@@ -99,14 +93,15 @@ class Mapper extends \LeanMapper\DefaultMapper
{
$namespace
=
self
::
getNamespaceFromClass
(
$class
);
if
(
empty
(
$namespace
))
if
(
empty
(
$namespace
))
{
throw
new
\InvalidArgumentException
(
'Method getTableFromClass received invalid (empty) parameter.'
);
}
$table
=
array_search
(
$namespace
,
$this
->
tableMapping
);
if
(
$table
!==
FALSE
)
if
(
$table
!==
FALSE
)
{
return
$table
;
else
{
}
else
{
if
(
strpos
(
$namespace
,
$this
->
baseNamespace
)
===
0
)
{
$namespace
=
str_replace
(
$this
->
baseNamespace
,
''
,
$namespace
);
}
else
{
...
...
src/LeanMapperWorkflow/Repository.php
View file @
e9c054c2
...
...
@@ -144,6 +144,7 @@ class Repository extends AbstractRepository
if
(
!
class_exists
(
$restriction
))
{
$restriction
=
'LeanMapperWorkflow\\Restriction'
;
}
return
new
$restriction
(
$this
->
mapper
);
}
...
...
src/LeanMapperWorkflow/Restriction.php
View file @
e9c054c2
...
...
@@ -23,7 +23,7 @@ class Restriction extends AbstractRestriction
*/
public
function
apply
(
\DibiFluent
$statement
,
Repository
$repository
,
$flag
=
NULL
)
{
if
(
isset
(
$this
->
id
))
{
if
(
isset
(
$this
->
id
))
{
if
(
is_array
(
$this
->
id
))
{
if
(
count
(
$this
->
id
)
===
0
)
{
throw
new
\UnexpectedValueException
(
'There must be provided at least one id'
);
...
...
@@ -35,11 +35,13 @@ class Restriction extends AbstractRestriction
}
}
if
(
isset
(
$this
->
limit
)
&&
$flag
!==
self
::
FLAG_COUNT
)
if
(
isset
(
$this
->
limit
)
&&
$flag
!==
self
::
FLAG_COUNT
)
{
$statement
->
limit
(
$this
->
limit
);
}
if
(
isset
(
$this
->
offset
)
&&
$flag
!==
self
::
FLAG_COUNT
)
if
(
isset
(
$this
->
offset
)
&&
$flag
!==
self
::
FLAG_COUNT
)
{
$statement
->
offset
(
$this
->
offset
);
}
}
...
...
@@ -53,6 +55,8 @@ class Restriction extends AbstractRestriction
return
$this
->
mapper
->
getTableByRepositoryClass
(
get_class
(
$repository
));
}
public
function
refreshJoins
()
{
foreach
(
$this
->
joins
as
&
$join
)
{
...
...
src/LeanMapperWorkflow/Traits/FindEntity.php
View file @
e9c054c2
...
...
@@ -3,6 +3,7 @@
namespace
LeanMapperWorkflow\Traits
;
use
LeanMapperWorkflow\Repository
;
use
Nette\Application\IPresenter
;
trait
FindEntity
...
...
@@ -18,8 +19,8 @@ trait FindEntity
*/
protected
final
function
findEntity
(
Repository
$repository
,
$id
,
$showMessage
=
FALSE
,
$redirectLink
=
NULL
)
{
if
(
$this
instanceof
\Nette\Application\
IPresenter
&&
(
$showMessage
!==
FALSE
||
$redirectLink
!==
NULL
))
{
$
c
allback
=
function
()
use
(
$showMessage
,
$redirectLink
)
{
if
(
$this
instanceof
IPresenter
&&
(
$showMessage
!==
FALSE
||
$redirectLink
!==
NULL
))
{
$
notFoundC
allback
=
function
()
use
(
$showMessage
,
$redirectLink
)
{
if
(
$showMessage
)
{
$this
->
flashMessage
(
'@todo'
,
'error'
);
}
...
...
@@ -29,10 +30,10 @@ trait FindEntity
}
};
}
else
{
$
c
allback
=
NULL
;
$
notFoundC
allback
=
NULL
;
}
return
$repository
->
find
(
$id
,
$
c
allback
);
return
$repository
->
find
(
$id
,
$
notFoundC
allback
);
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment