Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
R
restable
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
terranet
restable
Commits
a0d770ab
Commit
a0d770ab
authored
Mar 05, 2015
by
endi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Fractal Decorator
parent
b681c425
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
165 additions
and
0 deletions
+165
-0
FractalDecorator.php
src/FractalDecorator.php
+165
-0
No files found.
src/FractalDecorator.php
0 → 100644
View file @
a0d770ab
<?php
namespace
Terranet\Restable
;
use
Fractal
;
use
Illuminate\Contracts\Routing\ResponseFactory
;
use
Illuminate\Support\MessageBag
;
use
Illuminate\Contracts\Support\MessageProvider
AS
MessageProviderInterface
;
use
Illuminate\Support\Facades\Response
as
LaravelResponse
;
use
League\Fractal\Resource\Collection
;
use
League\Fractal\Resource\Item
;
use
Terranet\Restable\Contracts\SelfRendered
;
class
FractalDecorator
implements
SelfRendered
{
/**
* @var SelfRendered
*/
private
$selfRendered
;
public
function
__construct
(
SelfRendered
$selfRendered
)
{
$this
->
selfRendered
=
$selfRendered
;
}
/**
* Response listing.
*
* @param mixed array|object $collection
* @param null $transformer
* @return string
*/
public
function
listing
(
$collection
,
$transformer
=
null
)
{
return
$this
->
selfRendered
->
listing
(
$this
->
fractalCollection
(
$collection
,
$transformer
)
);
}
/**
* Response single.
*
* @param array $object $object
* @param null $transformer
* @return string
*/
public
function
single
(
$object
,
$transformer
=
null
)
{
return
$this
->
selfRendered
->
single
(
$this
->
fractalItem
(
$object
,
$transformer
)
);
}
/**
* Response created.
*
* @param array $object
* @param null $transformer
* @return string
*/
public
function
created
(
$object
,
$transformer
=
null
)
{
return
$this
->
selfRendered
->
created
(
$this
->
fractalItem
(
$object
,
$transformer
)
);
}
/**
* Response updated.
*
* @param array $object
* @param null $transformer
* @return string
*/
public
function
updated
(
$object
,
$transformer
=
null
)
{
return
$this
->
selfRendered
->
updated
(
$this
->
fractalItem
(
$object
,
$transformer
)
);
}
/**
* @param $object
* @param $transformer
* @return \League\Fractal\Scope
*/
protected
function
fractalItem
(
$object
,
$transformer
)
{
return
Fractal
::
createData
(
new
Item
(
$object
,
$transformer
));
}
/**
* @param $collection
* @param $transformer
* @return \League\Fractal\Scope
*/
protected
function
fractalCollection
(
$collection
,
$transformer
)
{
return
Fractal
::
createData
(
new
Collection
(
$collection
,
$transformer
));
}
/**
* Response deleted.
*
* @return string
*/
public
function
deleted
()
{
return
$this
->
selfRendered
->
deleted
();
}
/**
* Simple response success.
*
* @param mixed $message
* @return string
*/
public
function
success
(
$message
)
{
return
$this
->
selfRendered
->
success
(
$message
);
}
/**
* Unauthorized.
*
* @param mixed $description
* @return string
*/
public
function
unauthorized
(
$description
=
null
)
{
return
$this
->
selfRendered
->
unauthorized
(
$description
);
}
/**
* Any error return 400 as bad request.
*
* @param mixed $description
* @return string
*/
public
function
bad
(
$description
=
null
)
{
return
$this
->
selfRendered
->
bad
(
$description
);
}
/**
* Alias of error 404 response.
*
* @param array $description
* @return string
*/
public
function
missing
(
$description
=
null
)
{
return
$this
->
selfRendered
->
missing
(
$description
);
}
/**
* Alias of error 422 response.
*
* @param array $error
* @return string
*/
public
function
unprocess
(
$error
)
{
return
$this
->
selfRendered
->
unprocess
(
$error
);
}
}
\ 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