hiqdev /
payment-icons
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * 50+ icons for payment systems and methods |
||
| 4 | * |
||
| 5 | * @link https://github.com/hiqdev/payment-icons |
||
| 6 | * @package payment-icons |
||
| 7 | * @license MIT |
||
| 8 | * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace hiqdev\paymenticons\console; |
||
| 12 | |||
| 13 | use hidev\helpers\FileHelper; |
||
| 14 | use Yii; |
||
| 15 | |||
| 16 | class DoController extends \yii\console\Controller |
||
| 17 | { |
||
| 18 | private $iconsList; |
||
| 19 | private $uniqueIconsList; |
||
| 20 | private $packageRootDir = __DIR__ . '/../..'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Returns list of icons. |
||
| 24 | * @return array file path => name |
||
| 25 | */ |
||
| 26 | public function getUniqueIconsList() |
||
| 27 | { |
||
| 28 | if ($this->uniqueIconsList === null) { |
||
| 29 | $this->uniqueIconsList = $this->fetchUniqueIconsList(); |
||
| 30 | } |
||
| 31 | |||
| 32 | return $this->uniqueIconsList; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Fetches list of unique icons. |
||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | public function fetchUniqueIconsList() |
||
| 40 | { |
||
| 41 | $md5s = []; |
||
| 42 | foreach ($this->getIconsList() as $path => $name) { |
||
| 43 | $hash = md5_file($path); |
||
| 44 | if (in_array($hash, $md5s, true)) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | $md5s[$path] = $hash; |
||
| 48 | $list[$path] = $name; |
||
| 49 | } |
||
| 50 | |||
| 51 | return $list; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Returns list of icons. |
||
| 56 | * @return array file path => name |
||
| 57 | */ |
||
| 58 | public function getIconsList() |
||
| 59 | { |
||
| 60 | if ($this->iconsList === null) { |
||
| 61 | $this->iconsList = $this->fetchIconsList(); |
||
| 62 | } |
||
| 63 | |||
| 64 | return $this->iconsList; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Scans directory to prepare list of icons. |
||
| 69 | * @return array |
||
| 70 | */ |
||
| 71 | public function fetchIconsList() |
||
| 72 | { |
||
| 73 | $dir = $this->packageRootDir . '/src/assets/png/xs'; |
||
| 74 | $files = scandir($dir); |
||
| 75 | $list = []; |
||
| 76 | foreach ($files as $file) { |
||
| 77 | if ($file[0] === '.') { |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | $name = pathinfo($file)['filename']; |
||
| 81 | $list["$dir/$file"] = $name; |
||
| 82 | } |
||
| 83 | |||
| 84 | return $list; |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Generates CSS file. |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public function genCss() |
||
| 92 | { |
||
| 93 | $sizes = [ |
||
| 94 | 'xs' => 'height: 38px; width: 60px;', |
||
| 95 | 'sm' => 'height: 75px; width: 120px;', |
||
| 96 | 'md' => 'height: 240px; width: 150px;', |
||
| 97 | 'lg' => 'height: 480px; width: 300px;', |
||
| 98 | ]; |
||
| 99 | |||
| 100 | $res = '.pi { display: inline-block;height: 38px;width: 60px; }' . PHP_EOL; |
||
| 101 | |||
| 102 | foreach (array_keys($sizes) as $size) { |
||
| 103 | $res .= ".pi.pi-$size { $sizes[$size] }" . PHP_EOL; |
||
| 104 | } |
||
| 105 | |||
| 106 | foreach (array_keys($sizes) as $size) { |
||
| 107 | foreach ($this->getIconsList() as $name) { |
||
| 108 | if ($size === 'xs') { |
||
| 109 | $res .= ".pi.pi-$size.pi-$name, .pi.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; |
||
| 110 | } else { |
||
| 111 | $res .= ".pi.pi-$size.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | $res .= PHP_EOL; |
||
| 115 | } |
||
| 116 | |||
| 117 | return $res; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function actionGenCss() |
||
| 121 | { |
||
| 122 | echo $this->genCss(); |
||
| 123 | } |
||
| 124 | |||
| 125 | public function actionWriteCss() |
||
| 126 | { |
||
| 127 | FileHelper::write($this->packageRootDir . '/src/assets/css/payment-icons.css', $this->genCss()); |
||
| 128 | } |
||
| 129 | |||
| 130 | public function actionWritePreviews() |
||
| 131 | { |
||
| 132 | $sizes = ['xs', 'sm', 'md', 'lg']; |
||
| 133 | |||
| 134 | foreach ($sizes as $size) { |
||
| 135 | $str = ''; |
||
| 136 | foreach ($this->getUniqueIconsList() as $name) { |
||
| 137 | $str .= "\n"; |
||
| 138 | } |
||
| 139 | FileHelper::write($this->packageRootDir . '/docs/Preview' . strtoupper($size) . '.md', $str); |
||
| 140 | if ($size === 'xs') { |
||
| 141 | $ps = []; |
||
| 142 | foreach ($sizes as $s) { |
||
| 143 | $us = strtoupper($s); |
||
| 144 | $ps[] = "[$us](docs/Preview$us.md)"; |
||
| 145 | } |
||
| 146 | $str .= "\n" . implode(' | ', $ps); |
||
| 147 | FileHelper::write($this->packageRootDir . '/docs/readme/Preview.md', $str); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 |