@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Sonar\Common\Imports; |
3 | 3 | |
4 | 4 | use Symfony\Component\Yaml\Yaml; |
5 | -use Symfony\Component\Yaml\Exception\ParseException; |
|
6 | 5 | use File; |
7 | 6 | |
8 | 7 | abstract class AbstractImport |
@@ -10,34 +10,34 @@ discard block |
||
10 | 10 | protected $config; |
11 | 11 | private $filesystem; |
12 | 12 | |
13 | - public function __construct(Filesystem $filesystem=null) |
|
13 | + public function __construct(Filesystem $filesystem = null) |
|
14 | 14 | { |
15 | 15 | $this->config = []; |
16 | 16 | $this->filesystem = $filesystem ? $filesystem : new Filesystem; |
17 | 17 | } |
18 | 18 | |
19 | - public function setConfig($config_file,$is_force=false) |
|
19 | + public function setConfig($config_file, $is_force = false) |
|
20 | 20 | { |
21 | 21 | $config = Yaml::parse($config_file); |
22 | - if ( is_array($config) === false || $is_force ) { |
|
22 | + if (is_array($config) === false || $is_force) { |
|
23 | 23 | $config = Yaml::parse($this->filesystem->get($config_file)); |
24 | 24 | } |
25 | - if ( is_array($config) ) { |
|
26 | - $this->config = array_merge($this->config,$config); |
|
25 | + if (is_array($config)) { |
|
26 | + $this->config = array_merge($this->config, $config); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | public function getConfig() |
30 | 30 | { |
31 | 31 | return $this->config; |
32 | 32 | } |
33 | - public function setModels($models,$csv) |
|
33 | + public function setModels($models, $csv) |
|
34 | 34 | { |
35 | - foreach ( $models as $table => $model ) { |
|
36 | - if ( is_array($model) ) { |
|
35 | + foreach ($models as $table => $model) { |
|
36 | + if (is_array($model)) { |
|
37 | 37 | $total = count($model); |
38 | - for($i=0;$i<$total;$i++) { |
|
39 | - if ( isset($this->config[$table][$i]) ) { |
|
40 | - $this->setModel($model[$i],$this->config[$table][$i],$csv,$table); |
|
38 | + for ($i = 0; $i < $total; $i++) { |
|
39 | + if (isset($this->config[$table][$i])) { |
|
40 | + $this->setModel($model[$i], $this->config[$table][$i], $csv, $table); |
|
41 | 41 | } else { |
42 | 42 | throw new \Exception('設定ファイルが正しくないか、構成が異なっています。table=' . $table); |
43 | 43 | } |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | return true; |
48 | 48 | } |
49 | 49 | |
50 | - public function setModel($model,$config,$csv,$table) |
|
50 | + public function setModel($model, $config, $csv, $table) |
|
51 | 51 | { |
52 | - foreach ( $config as $key => $rec ) { |
|
53 | - if ( isset($rec['func']) === true && $rec['func'] ) { |
|
52 | + foreach ($config as $key => $rec) { |
|
53 | + if (isset($rec['func']) === true && $rec['func']) { |
|
54 | 54 | $func = $rec['func']; |
55 | 55 | $col = isset($rec['csv']) ? $rec['csv'] : null; |
56 | - if ( strpos($col,",") !== false ) { |
|
57 | - $col = explode(",",$col); |
|
56 | + if (strpos($col, ",") !== false) { |
|
57 | + $col = explode(",", $col); |
|
58 | 58 | } |
59 | - if ( method_exists($this,$func) === true ) { |
|
60 | - $this->$func($model,$key,$csv,$col); |
|
59 | + if (method_exists($this, $func) === true) { |
|
60 | + $this->$func($model, $key, $csv, $col); |
|
61 | 61 | } else { |
62 | 62 | throw new \Exception(get_class($this) . 'に関数=' . $func . 'が実装されていません。'); |
63 | 63 | } |
64 | - } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) === true && isset($csv[($rec['csv']+0)-1]) ) { |
|
64 | + } elseif (isset($rec['csv']) && is_numeric($rec['csv']) === true && isset($csv[($rec['csv']+0)-1])) { |
|
65 | 65 | $model->$key = $csv[($rec['csv']+0)-1]; |
66 | - } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) === false && isset($csv[$rec['csv']]) ) { |
|
66 | + } elseif (isset($rec['csv']) && is_numeric($rec['csv']) === false && isset($csv[$rec['csv']])) { |
|
67 | 67 | $model->$key = $csv[$rec['csv']]; |
68 | 68 | } else { |
69 | 69 | $model->$key = null; |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! function_exists('strcat') ) { |
|
3 | +if ( ! function_exists('strcat')) { |
|
4 | 4 | function strcat() |
5 | 5 | { |
6 | 6 | $args = func_get_args(); |
7 | 7 | $str = ''; |
8 | 8 | |
9 | - foreach ( $args as $rec ) { |
|
10 | - if ( $rec ) { |
|
9 | + foreach ($args as $rec) { |
|
10 | + if ($rec) { |
|
11 | 11 | $str .= $rec; |
12 | 12 | } else { |
13 | 13 | return null; |
@@ -1,29 +1,29 @@ |
||
1 | 1 | <?php |
2 | 2 | use Carbon\Carbon; |
3 | 3 | |
4 | -if ( ! function_exists('strtodate') ) { |
|
5 | - function strtodate($date,$format='Y/m/d') |
|
4 | +if ( ! function_exists('strtodate')) { |
|
5 | + function strtodate($date, $format = 'Y/m/d') |
|
6 | 6 | { |
7 | - if ( $date ) { |
|
8 | - return date($format,strtotime($date)); |
|
7 | + if ($date) { |
|
8 | + return date($format, strtotime($date)); |
|
9 | 9 | } |
10 | 10 | return null; |
11 | 11 | } |
12 | 12 | } |
13 | 13 | |
14 | -if ( ! function_exists('ym') ) { |
|
14 | +if ( ! function_exists('ym')) { |
|
15 | 15 | function ym($ym) |
16 | 16 | { |
17 | - if ( $ym && $ym > 190001 ) { |
|
18 | - return (floor($ym/100)) . '年' . ( floor($ym%100)) . '月'; |
|
17 | + if ($ym && $ym > 190001) { |
|
18 | + return (floor($ym/100)) . '年' . (floor($ym%100)) . '月'; |
|
19 | 19 | } |
20 | 20 | return null; |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | -if ( ! function_exists('elapse_days') ) { |
|
24 | +if ( ! function_exists('elapse_days')) { |
|
25 | 25 | function elapse_days($timestamp) |
26 | 26 | { |
27 | - return Carbon::createFromTimeStamp($timestamp)->diffInDays(Carbon::now(),false); |
|
27 | + return Carbon::createFromTimeStamp($timestamp)->diffInDays(Carbon::now(), false); |
|
28 | 28 | } |
29 | 29 | } |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! function_exists('numeric_format') ) { |
|
3 | +if ( ! function_exists('numeric_format')) { |
|
4 | 4 | function numeric_format($val) |
5 | 5 | { |
6 | - $number = str_replace(",","",$val); |
|
6 | + $number = str_replace(",", "", $val); |
|
7 | 7 | |
8 | - if ( is_numeric($number) ) { |
|
9 | - $number = number_format($number,8); |
|
10 | - $number = preg_replace('/\.0+$/','',$number); |
|
11 | - $number = preg_replace('/(\.[0-9]*?)0+$/',"$1",$number); |
|
8 | + if (is_numeric($number)) { |
|
9 | + $number = number_format($number, 8); |
|
10 | + $number = preg_replace('/\.0+$/', '', $number); |
|
11 | + $number = preg_replace('/(\.[0-9]*?)0+$/', "$1", $number); |
|
12 | 12 | } |
13 | 13 | return $number; |
14 | 14 | } |
@@ -5,11 +5,11 @@ |
||
5 | 5 | { |
6 | 6 | abstract public function csvRecord(array $record); |
7 | 7 | |
8 | - public function csvRead($file,$delimiter=",",$envlosure='"',$escape="\\",$length=1024*1024) |
|
8 | + public function csvRead($file, $delimiter = ",", $envlosure = '"', $escape = "\\", $length = 1024*1024) |
|
9 | 9 | { |
10 | - if ( ($fp = @fopen($file,"r")) !== false ) { |
|
10 | + if (($fp = @fopen($file, "r")) !== false) { |
|
11 | 11 | |
12 | - while(($data = fgetcsv($fp,$length,$delimiter,$envlosure,$escape)) !== false ) { |
|
12 | + while (($data = fgetcsv($fp, $length, $delimiter, $envlosure, $escape)) !== false) { |
|
13 | 13 | $this->csvRecord($data); |
14 | 14 | } |
15 | 15 | fclose($fp); |
@@ -9,7 +9,7 @@ |
||
9 | 9 | { |
10 | 10 | |
11 | 11 | } |
12 | - public function setName($model,$key,$csv,$col) |
|
12 | + public function setName($model, $key, $csv, $col) |
|
13 | 13 | { |
14 | 14 | |
15 | 15 | } |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | { |
19 | 19 | $tree = isset($this->tree) ? $this->tree : []; |
20 | 20 | |
21 | - foreach ( $data as $rec ) { |
|
22 | - if ( is_object($rec) === false ) throw new Exception('data record must be object.'); |
|
23 | - if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".'); |
|
24 | - if ( isset($rec->parent_id) === false || ! $rec->parent_id ) { |
|
21 | + foreach ($data as $rec) { |
|
22 | + if (is_object($rec) === false) throw new Exception('data record must be object.'); |
|
23 | + if (isset($rec->id) === false) throw new Exception('data record object does not have property => "id".'); |
|
24 | + if (isset($rec->parent_id) === false || ! $rec->parent_id) { |
|
25 | 25 | $rec->children = []; |
26 | 26 | $tree[$rec->id] = $rec; |
27 | 27 | } else { |
28 | - $this->addTree($tree,$rec); |
|
28 | + $this->addTree($tree, $rec); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | $this->tree = $tree; |
32 | 32 | } |
33 | - protected function addTree(&$tree,$data) |
|
33 | + protected function addTree(&$tree, $data) |
|
34 | 34 | { |
35 | - foreach ( $tree as $id => &$rec ) { |
|
36 | - if ( $data->parent_id == $id ) { |
|
35 | + foreach ($tree as $id => &$rec) { |
|
36 | + if ($data->parent_id == $id) { |
|
37 | 37 | $data->children = []; |
38 | 38 | $rec->children[$data->id] = $data; |
39 | 39 | return; |
40 | - } elseif ( count($rec->children) ) { |
|
41 | - $this->addTree($rec->children,$data); |
|
40 | + } elseif (count($rec->children)) { |
|
41 | + $this->addTree($rec->children, $data); |
|
42 | 42 | } |
43 | 43 | unset($rec); |
44 | 44 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | public function mergeCount($count_data) |
47 | 47 | { |
48 | 48 | $tree = isset($this->tree) ? $this->tree : []; |
49 | - foreach ( $tree as &$rec ) { |
|
50 | - foreach ( $count_data as $count ) { |
|
51 | - if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".'); |
|
52 | - if ( isset($count->id) === false ) throw new Exception('count data record object does not have property => "id".'); |
|
53 | - if ( isset($count->count) === false ) throw new Exception('count data record object does not have property => "count".'); |
|
54 | - if ( $rec->id == $count->id ) { |
|
49 | + foreach ($tree as &$rec) { |
|
50 | + foreach ($count_data as $count) { |
|
51 | + if (isset($rec->id) === false) throw new Exception('data record object does not have property => "id".'); |
|
52 | + if (isset($count->id) === false) throw new Exception('count data record object does not have property => "id".'); |
|
53 | + if (isset($count->count) === false) throw new Exception('count data record object does not have property => "count".'); |
|
54 | + if ($rec->id == $count->id) { |
|
55 | 55 | $rec->count = $count->count; |
56 | 56 | } |
57 | 57 | } |
@@ -19,8 +19,12 @@ discard block |
||
19 | 19 | $tree = isset($this->tree) ? $this->tree : []; |
20 | 20 | |
21 | 21 | foreach ( $data as $rec ) { |
22 | - if ( is_object($rec) === false ) throw new Exception('data record must be object.'); |
|
23 | - if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".'); |
|
22 | + if ( is_object($rec) === false ) { |
|
23 | + throw new Exception('data record must be object.'); |
|
24 | + } |
|
25 | + if ( isset($rec->id) === false ) { |
|
26 | + throw new Exception('data record object does not have property => "id".'); |
|
27 | + } |
|
24 | 28 | if ( isset($rec->parent_id) === false || ! $rec->parent_id ) { |
25 | 29 | $rec->children = []; |
26 | 30 | $tree[$rec->id] = $rec; |
@@ -48,9 +52,15 @@ discard block |
||
48 | 52 | $tree = isset($this->tree) ? $this->tree : []; |
49 | 53 | foreach ( $tree as &$rec ) { |
50 | 54 | foreach ( $count_data as $count ) { |
51 | - if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".'); |
|
52 | - if ( isset($count->id) === false ) throw new Exception('count data record object does not have property => "id".'); |
|
53 | - if ( isset($count->count) === false ) throw new Exception('count data record object does not have property => "count".'); |
|
55 | + if ( isset($rec->id) === false ) { |
|
56 | + throw new Exception('data record object does not have property => "id".'); |
|
57 | + } |
|
58 | + if ( isset($count->id) === false ) { |
|
59 | + throw new Exception('count data record object does not have property => "id".'); |
|
60 | + } |
|
61 | + if ( isset($count->count) === false ) { |
|
62 | + throw new Exception('count data record object does not have property => "count".'); |
|
63 | + } |
|
54 | 64 | if ( $rec->id == $count->id ) { |
55 | 65 | $rec->count = $count->count; |
56 | 66 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | { |
8 | 8 | private $filesystem; |
9 | 9 | |
10 | - public function __construct($app,Filesystem $file=null) |
|
10 | + public function __construct($app, Filesystem $file = null) |
|
11 | 11 | { |
12 | 12 | parent::__construct($app); |
13 | 13 | |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | } |
16 | 16 | public function register() |
17 | 17 | { |
18 | - foreach ( $this->filesystem->allFiles(__DIR__ . '/Helpers') as $rec ) { |
|
19 | - if ( preg_match("/\.php$/",$rec->getFilename()) ) { |
|
18 | + foreach ($this->filesystem->allFiles(__DIR__ . '/Helpers') as $rec) { |
|
19 | + if (preg_match("/\.php$/", $rec->getFilename())) { |
|
20 | 20 | require_once($rec->getPathname()); |
21 | 21 | } |
22 | 22 | } |