Skip to content

Commit

Permalink
Merge pull request #12 from tsukabo/dev/cake5
Browse files Browse the repository at this point in the history
CakePHP5に対応させる
  • Loading branch information
kozo authored Nov 21, 2023
2 parents a1b96de + 42144cb commit b3b47e3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.phar
/composer.lock
/vendor
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Partial Plugin is CakePHP element of small scope.
## Installation

```
composer require kozo/partial:"~3.0"
composer require kozo/partial:"~5.0"
```


## Usage

AppView.php
```
use Partial\View\PartialTrait;
class AppView extends View {
class AppView extends View
{
use PartialTrait;
}
```
Expand Down
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
"role": "Author"
}],
"require": {
"cakephp/cakephp": "~3.5|~4.0",
"cakephp/plugin-installer": "*"
"php": ">=8.1.0",
"cakephp/cakephp": "~5.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "*"
},
"extra": {
"installer-name": "Partial"
Expand All @@ -21,5 +24,14 @@
"psr-4": {
"Partial\\": "src"
}
},
"scripts": {
"phpcs": "phpcs --colors -p -s --standard=CakePHP src/",
"phpcbf": "phpcbf --colors --parallel=16 -p src/"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
30 changes: 20 additions & 10 deletions src/View/PartialTrait.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<?php
declare(strict_types=1);

namespace Partial\View;

use Cake\View\Exception\MissingElementException;

trait PartialTrait {
public $partialCache = 'partial';
trait PartialTrait
{
public string $partialCache = 'partial';

public function partial($name, array $data = array(), array $options = array()) {
/**
* @param string $name
* @param array $data
* @param array $options
* @return array|string
* @throws \Cake\View\Exception\MissingElementException
*/
public function partial(string $name, array $data = [], array $options = []): array|string
{
$file = $plugin = null;

if (!isset($options['callbacks'])) {
Expand All @@ -27,21 +37,20 @@ public function partial($name, array $data = array(), array $options = array())
}

if (empty($options['ignoreMissing'])) {
list ($plugin, $name) = pluginSplit($name, true);
[$plugin, $name] = $this->pluginSplit($name, true);
$name = str_replace('/', DS, $name);
$file = $plugin . $this->templatePath . DS . '_' . $name . $this->_ext;
throw new MissingElementException($file);
}
}

/**
* ファイル名を取得する
*
* @access private
* @author sakuragawa
* @param string $name
* @return string|bool
*/
protected function _getPartialFileName($name) {
list($plugin, $name) = $this->pluginSplit($name);
protected function _getPartialFileName(string $name): string|bool
{
[$plugin, $name] = $this->pluginSplit($name);

$paths = $this->_paths($plugin);

Expand All @@ -55,6 +64,7 @@ protected function _getPartialFileName($name) {
return $path . $this->getTemplatePath() . DS . $name . $this->_ext;
}
}

return false;
}
}

0 comments on commit b3b47e3

Please sign in to comment.