/** * @dataProvider database_items_batch */ public function test_raw_data($item) { $f = BASE_DIR . '/var/cache/test/file.test'; \System\Directory::check(BASE_DIR . '/var/cache/test'); file_put_contents($f, 'test'); $item = new \Test\Model\Mock\Database($item); $data = $item->get_data_raw(); $obj = $item->to_object(); if ($item->belongs) { $this->assertFalse(array_key_exists('belongs', $data)); $this->assertTrue(array_key_exists('id_belongs', $data)); } if ($item->belongs_def) { $this->assertFalse(array_key_exists('belongs', $data)); $this->assertTrue(array_key_exists('id_belongs_def', $data)); } if ($item->belongs_null) { $this->assertFalse(array_key_exists('belongs_null', $data)); $this->assertTrue(array_key_exists('id_belongs_null', $data)); } if ($item->file) { $this->assertTrue(array_key_exists('file', $data)); $this->assertTrue(is_string($data['file'])); $file = json_decode($data['file'], true); $this->assertTrue(array_key_exists('hash', $file)); $this->assertEquals($item->file->hash, $file['hash']); } unlink($f); }
public function construct($attrs) { \System\Directory::check(BASE_DIR . self::DIR_CACHE); $cache = \System\Settings::getSafe(array('cache', 'templates'), true); if (class_exists('Jade\\Jade')) { $this->jade = new \Jade\Jade(array('cache' => $cache ? BASE_DIR . self::DIR_CACHE : null)); } else { throw new \System\Error\MissingDependency('Could not find jade template compiler.', 'Please install ronan-gloo/jadephp'); } }
/** * Write error into log file * * @param string $type * @param string $msg * @return void */ public static function report($type, $report) { $debug = \System\Settings::getSafe(array('dev', 'debug', 'backend'), false); \System\Directory::check(BASE_DIR . self::DIR_LOGS); $log_to = fopen(BASE_DIR . self::DIR_LOGS . '/' . $type . '.log', 'a+'); if (!$debug && $type == 'error') { $rcpt = \System\Settings::getSafe(array('dev', 'mailing', 'errors'), null); if ($rcpt) { \Helper\Offcom\Mail::create('[Fudjan] Server error', $report, $rcpt)->send(); } } if (is_resource($log_to)) { fwrite($log_to, $report); } }
/** * @returns array List of directories */ public static function list_dirs($relative_path) { $list = array(); $libs = self::get_libs(); if (is_dir(ROOT . $relative_path)) { $list[] = realpath(ROOT . $relative_path); } foreach ($libs as $lib) { $dir = BASE_DIR . self::DIR_VENDOR . '/' . $lib . '/' . $relative_path; if (\System\Directory::check($dir, false)) { $list[] = realpath($dir); } } if (BASE_DIR != ROOT && is_dir(BASE_DIR . $relative_path)) { $list[] = realpath(BASE_DIR . $relative_path); } return array_unique($list); }
public function cmd_artifact(array $params = array()) { \System\Directory::check(BASE_DIR . static::DIR_PACKAGES); $target = BASE_DIR . static::DIR_PACKAGES . '/artifact.tar'; $result = $target . '.gz'; if (isset($params[0])) { $target = $params[0]; } if (file_exists($target)) { unlink($target); } if (file_exists($result)) { unlink($result); } $iter = new \RecursiveDirectoryIterator(BASE_DIR); $iter->setFlags(\FileSystemIterator::SKIP_DOTS); $iter = new ProjectDirectoryRecursiveIterator($iter); $iter = new \RecursiveIteratorIterator($iter); $archive = new \PharData($target); $archive->buildFromIterator($iter, BASE_DIR); $archive->compress(\Phar::GZ); unlink($target); }
/** Read all JSON files in dir and return content * @param string $dir_dist Path to directory * @param &array $temp Variable to write in * @param bool $assoc_keys Associate file names (without postifx) to data read * @param &array $files Files that have been read during dist search * @return array */ public static function read_dist($dir_dist, &$temp = array(), $assoc_keys = false, &$files = array()) { if (\System\Directory::check($dir_dist, false)) { $dir = opendir($dir_dist); while ($f = readdir($dir)) { if (strpos($f, ".") !== 0 && strpos($f, ".json")) { list($mod) = explode(".", $f); $json = (array) self::read($dir_dist . '/' . $f); $files[] = $dir_dist . '/' . $f; if ($assoc_keys) { if (isset($temp[$mod])) { if (isset($json['overwrite']) && $json['overwrite']) { unset($json['overwrite']); $temp[$mod] = $json; } else { $temp[$mod] = array_replace_recursive($temp[$mod], $json); } } else { unset($json['overwrite']); $temp[$mod] = $json; } } else { if (isset($json['overwrite']) && $json['overwrite']) { unset($json['overwrite']); $temp = $json; } else { $temp = array_merge_recursive($temp, $json); } } } } closedir($dir); return $temp; } else { throw new \System\Error\File(sprintf('Directory "%s" either does not exist or is not accessible.', $dir_dist)); } }
/** Does config environment exist * @param string $env Environment name * @return bool */ public static function env_create($env) { return \System\Directory::check(BASE_DIR . self::DIR_CONF_DIST . '/' . $env); }
/** Generate thumb using GD library * @param self $obj Instance of image * @return bool */ public static function gen_gd(self $obj) { $obj->image->refresh_info(); $coords = array('w_new' => $obj->width, 'h_new' => $obj->height, 'w_org' => intval($obj->image->width()), 'h_org' => intval($obj->image->height())); $tpth = BASE_DIR . $obj->get_path(); \System\Directory::check(dirname($tpth)); if ($coords['w_new'] < $coords['w_org'] || $coords['h_new'] < $coords['h_org']) { $coords = self::calc_thumb_coords($coords, $obj->crop); $im = \System\Image::get_gd_resource($obj->image); $th = imagecreatetruecolor($coords['w_new'], $coords['h_new']); $trans = $obj->image->format() == 3; if ($trans) { $transparent = imagecolorallocatealpha($th, 0, 0, 0, 127); imagefill($th, 0, 0, $transparent); } else { $wh = imagecolorallocate($th, 255, 255, 255); imagefill($th, 0, 0, $wh); } imagecopyresampled($th, $im, intval($coords['dst_x']), intval($coords['dst_y']), 0, 0, intval($coords['xw']), intval($coords['xh']), $coords['w_org'], $coords['h_org']); if (file_exists($tpth)) { unlink($tpth); } if ($trans) { imagealphablending($th, false); imagesavealpha($th, true); imagepng($th, $tpth); } else { imagejpeg($th, $tpth, 99); } imagedestroy($th); } else { $obj->image->copy($tpth); } return $obj; }
/** Read file data * @param string $path * @param bool $silent * @throws System\Error\File * @throws System\Error\Permissions * @return string */ public static function read($path, $silent = false) { if (\System\Directory::check(dirname($path), false) && file_exists($path)) { if (is_readable($path)) { return file_get_contents($path); } else { if (!$silent) { throw new \System\Error\Permissions(sprintf('Failed to read file "%s". It is not readable.', $path)); } } } else { if (!$silent) { throw new \System\Error\File(sprintf('Failed to read file "%s". It does not exist.', $path)); } } return false; }