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
1d867a92
Commit
1d867a92
authored
May 26, 2014
by
Tomas Lang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Entity: FindEntity trait
parent
839042b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
Repository.php
src/LeanMapperWorkflow/Repository.php
+7
-2
FindEntity.php
src/LeanMapperWorkflow/Traits/FindEntity.php
+38
-0
No files found.
src/LeanMapperWorkflow/Repository.php
View file @
1d867a92
...
...
@@ -14,12 +14,13 @@ class Repository extends AbstractRepository
/**
* @param int|Restriction $id
* @param callback|null $notFoundCallaback
*
* @return Entity
*
* @throws InvalidArgumentException
*/
public
function
find
(
$id
)
public
function
find
(
$id
,
$notFoundCallback
=
NULL
)
{
if
(
is_numeric
(
$id
))
{
$restriction
=
$this
->
createRestriction
();
...
...
@@ -35,7 +36,11 @@ class Repository extends AbstractRepository
$row
=
$statement
->
fetch
();
if
(
$row
===
FALSE
)
{
throw
new
\InvalidArgumentException
(
'Not found: '
.
var_export
(
$id
,
TRUE
));
if
(
is_callable
(
$notFoundCallback
))
{
\Nette\Utils\Callback
::
invokeArgs
(
$notFoundCallback
,
[
$id
]);
}
else
{
throw
new
InvalidArgumentException
(
'Not found: '
.
var_export
(
$id
,
TRUE
));
}
}
return
$this
->
createEntity
(
$row
);
...
...
src/LeanMapperWorkflow/Traits/FindEntity.php
0 → 100644
View file @
1d867a92
<?php
namespace
LeanMapperWorkflow\Traits
;
use
LeanMapperWorkflow\Repository
;
trait
FindEntity
{
/**
* @param Repository $repository
* @param mixed $id
* @param bool $showMessage
* @param string $redirectLink
*
* @throws \InvalidArgumentException
*/
protected
final
function
findEntity
(
Repository
$repository
,
$id
,
$showMessage
=
FALSE
,
$redirectLink
=
NULL
)
{
if
(
$this
instanceof
\Nette\Application\IPresenter
&&
(
$showMessage
!==
FALSE
||
$redirectLink
!==
NULL
))
{
$callback
=
function
()
use
(
$showMessage
,
$redirectLink
)
{
if
(
$showMessage
)
{
$this
->
flashMessage
(
'@todo'
,
'error'
);
}
if
(
$link
!==
NULL
)
{
$this
->
redirect
(
$link
);
}
};
}
else
{
$callback
=
NULL
;
}
return
$repository
->
find
(
$id
,
$callback
);
}
}
\ 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