-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] Implement anonymous components (#31363)
Implements class-less components.
- Loading branch information
1 parent
4288dbb
commit b1fe9eb
Showing
6 changed files
with
240 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Illuminate\View; | ||
|
||
class AnonymousComponent extends Component | ||
{ | ||
/** | ||
* The component view. | ||
* | ||
* @var string | ||
*/ | ||
protected $view; | ||
|
||
/** | ||
* The component data. | ||
* | ||
* @var array | ||
*/ | ||
protected $data = []; | ||
|
||
/** | ||
* Create a new class-less component instance. | ||
* | ||
* @param string $view | ||
* @param array $data | ||
* @return void | ||
*/ | ||
public function __construct($view, $data) | ||
{ | ||
$this->view = $view; | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* Get the view / view contents that represent the component. | ||
* | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
return $this->view; | ||
} | ||
|
||
/** | ||
* Get the data that should be supplied to the view. | ||
* | ||
* @return array | ||
*/ | ||
public function data() | ||
{ | ||
$this->attributes = $this->attributes ?: new ComponentAttributeBag; | ||
|
||
return $this->data + ['attributes' => $this->attributes]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters