/** * Generator constructor. * * @param array $params * @uses Generator::$file_path */ public function __construct(array $params) { parent::__construct($params); // generated file must be outside of the namespace $this->directory = PHP_DIR; if (Helpers::is_array_ne($params)) { if (array_key_exists('file_name', $params)) { $this->setFileName($params['file_name']); } } $this->file_path = $this->directory . DIRECTORY_SEPARATOR . $this->file_name; $this->Log->write('file_path', Log::LOG_LEVEL_USER, $this->file_path); }
/** * ParseSql constructor. * * @param array $params */ public function __construct($params = array()) { $this->log_file = 'parse_sql_' . date('Y-m-d') . '.log'; // handle parameters if (Helpers::is_array_ne($params)) { // get directory if (array_key_exists('dir', $params) && Helpers::is_string_ne($params['dir'])) { $dir = realpath($params['dir']); if (Helpers::is_string_ne($dir)) { $this->dir = $dir . DIRECTORY_SEPARATOR; } } // get file name (and maybe directory name) if (array_key_exists('file', $params) && Helpers::is_string_ne($params['file'])) { if (file_exists($this->dir . $params['file'])) { // directory has been set properly and file exists $this->file = $params['file']; } elseif (file_exists($params['file'])) { // file is a full path, so split it to directory and file name $this->dir = dirname($params['file']) . DIRECTORY_SEPARATOR; $this->file = basename($params['file']); } elseif (file_exists(__DIR__ . DIRECTORY_SEPARATOR . $params['file'])) { // file exists in this directory, so set directory and file name $this->dir = __DIR__ . DIRECTORY_SEPARATOR; $this->file = $params['file']; } } if (array_key_exists('log_level', $params) && Helpers::is_valid_int($params['log_level'])) { $this->log_level = $params['log_level']; } if (array_key_exists('log_directory', $params) && Helpers::is_string_ne($params['log_directory'])) { if (is_dir($params['log_directory'])) { $this->log_directory = $params['log_directory']; } else { $this->log_directory = LOG_DIR; } } if (array_key_exists('log_file', $params) && Helpers::is_string_ne($params['log_file'])) { $this->log_file = $params['log_file']; } } // set up Log $this->Log = new Log(['file' => $this->log_file, 'log_level' => $this->log_level, 'log_directory' => $this->log_directory]); // verify log file was set properly $log_file = $this->Log->file(); if ($log_file !== $this->log_file) { $this->Log->write('could not set file properly', Log::LOG_LEVEL_WARNING); } $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION); }
/** * Create a PHP array in the proper format with the relationship values. * * @return bool * @uses Generator::$iterator * @uses Relationship::$relationship_array */ protected function generate() { $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION); // input validation if (!$this->iterator instanceof DbIterator) { $this->Log->write('iterator is not valid', Log::LOG_LEVEL_WARNING, Helpers::get_type_size($this->iterator)); return false; } $array = array(); foreach ($this->iterator as $row) { if (!Helpers::is_string_ne($row['child_table'])) { continue; } if (!array_key_exists($row['child_table'], $array)) { $array[$row['child_table']] = array(); } $array[$row['child_table']][$row['child_field']] = array('table' => $row['parent_table'], 'field' => $row['parent_field']); } $this->relationship_array = $array; return Helpers::is_array_ne($this->relationship_array); }