/** * Fetches the directory object for the module with * the matching name. * * Each module and plug-in should store its project-specific data * in its own directory. * This function returns that directory. * * @param string $module_name The identifying name of the module. */ public static function get_directory($module_name) { if (HaddockProjectOrganisation_ModuleDirectoriesHelper::insist_module_directory_exists($module_name)) { $project_specific_directory = HaddockProjectOrganisation_ProjectSpecificDirectoryHelper::get_project_specific_directory(); $directory_name = $project_specific_directory->get_name() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . $module_name; FileSystem_DirectoryHelper::mkdir_parents($directory_name); return new FileSystem_Directory($directory_name); } }
public static function create_regex_validator($new_regex_validator_name, HaddockProjectOrganisation_ModuleDirectory $module_directory) { $classes_directory = $module_directory->get_classes_directory(); $input_validators_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'input-validation'; #echo '$input_validators_directory_name: ' . $input_validators_directory_name . PHP_EOL; FileSystem_DirectoryHelper::mkdir_parents($input_validators_directory_name); $input_validator_class_name = $module_directory->get_camel_case_root() . '_' . $new_regex_validator_name . 'Validator'; #echo '$input_validator_class_name: ' . $input_validator_class_name . PHP_EOL; $input_validator_file_name = $input_validators_directory_name . DIRECTORY_SEPARATOR . $input_validator_class_name . '.inc.php'; #echo '$input_validator_file_name: ' . $input_validator_file_name . PHP_EOL; if (is_file($input_validator_file_name)) { throw new ErrorHandling_SprintfException('\'%s\' already exists!', array($input_validator_file_name)); } else { $date = date('Y-m-d'); $copyright_holder = $module_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$input_validator_class_name} * * @copyright {$date}, {$copyright_holder} */ class \t{$input_validator_class_name} extends \tInputValidation_RegexValidator { \tprotected function \t\tget_regex() \t{ \t\t/* \t\t * Write the regex here. \t\t */ \t\treturn '/^\$/'; \t} \t \tprotected function \t\tget_exception_message() \t{ \t\t/* \t\t * Write a more informative exception message here. \t\t */ \t\treturn 'Regex validation error!'; \t} } ?> CNT; if ($fh = fopen($input_validator_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } }
/** * Gets the name of the project information directory. * * If the directory does not exist, then it can optionally be created. * * @param bool $create_directory_if_not_exists Whether the function should create the directory if it does not exist. * @return string The name of the directory containing the project information. */ public static function get_project_information_directory_name($create_directory_if_not_exists = FALSE) { $project_specific_directory = HaddockProjectOrganisation_ProjectSpecificDirectoryHelper::get_project_specific_directory(); $project_information_directory_name = $project_specific_directory->get_name() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'haddock-project-organisation'; if ($create_directory_if_not_exists) { if (!is_dir($project_information_directory_name)) { FileSystem_DirectoryHelper::mkdir_parents($project_information_directory_name); } } return $project_information_directory_name; }
public static function tear_down() { $dbh = Database_ConnectionsHelper::get_root_connection_using_cli(); $stmt = <<<SQL DROP TABLE hc_database_test_1; DROP TABLE hc_database_test_2; DROP TABLE hc_database_test_3; SQL; mysql_query($stmt, $dbh); FileSystem_DirectoryHelper::delete_recursively(self::get_table_specification_directory_name()); }
private static function get_default_location_directory_name($create_directory_if_not_exists = FALSE) { $project_specific_directory = HaddockProjectOrganisation_ProjectSpecificDirectoryHelper::get_project_specific_directory(); $default_location_directory_name = $project_specific_directory->get_name() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'public-html'; if ($create_directory_if_not_exists) { if (!is_dir($default_location_directory_name)) { FileSystem_DirectoryHelper::mkdir_parents($default_location_directory_name); } } return $default_location_directory_name; }
public static function create_cli_script($new_script_name, HaddockProjectOrganisation_ModuleDirectory $module_directory) { /* * TODO Make sure that the module directory has a classes directory first. * * If there is no classes directory, then such a directory should created. */ $module_directory->make_sure_classes_directory_exists(); $classes_directory = $module_directory->get_classes_directory(); $cli_scripts_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'cli-scripts'; #echo '$cli_scripts_directory_name: ' . $cli_scripts_directory_name . PHP_EOL; FileSystem_DirectoryHelper::mkdir_parents($cli_scripts_directory_name); $script_class_name = $module_directory->get_camel_case_root() . '_' . $new_script_name . 'CLIScript'; #echo '$script_class_name: ' . $script_class_name . PHP_EOL; $cli_script_file_name = $cli_scripts_directory_name . DIRECTORY_SEPARATOR . $script_class_name . '.inc.php'; #echo '$cli_script_file_name: ' . $cli_script_file_name . PHP_EOL; if (is_file($cli_script_file_name)) { throw new ErrorHandling_SprintfException('\'%s\' already exists!', array($cli_script_file_name)); } else { $date = date('Y-m-d'); $copyright_holder = $module_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$script_class_name} * * @copyright {$date}, {$copyright_holder} */ class \t{$script_class_name} extends \tCLIScripts_CLIScript { \tpublic function \t\tdo_actions() \t{ \t\t/* \t\t * Write code here. \t\t */ \t} } ?> CNT; if ($fh = fopen($cli_script_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); CLIScripts_ScriptObjectRunnersHelper::generate_script_object_runners(); } } }
public static function set_name($name) { $validator = new HaddockProjectOrganisation_ProjectNameValidator(); if ($validator->validate($name)) { $name_file_name = self::get_name_file_name(); $project_information_directory_name = self::get_project_information_directory_name(); if (!is_dir($project_information_directory_name)) { #mkdir($project_information_directory_name); FileSystem_DirectoryHelper::mkdir_parents($project_information_directory_name); } if ($fh = fopen($name_file_name, 'w')) { fwrite($fh, $name . PHP_EOL); fclose($fh); } } }
public static function set_page_class_name($page_class_name) { $page_class_name = trim($page_class_name); $validator = new SiteTexts_PageClassNameValidator(); if ($validator->validate($page_class_name)) { #echo $page_class_name; $project_specific_config_directory_name = self::get_project_specific_config_directory_name(); if (!is_dir($project_specific_config_directory_name)) { FileSystem_DirectoryHelper::mkdir_parents($project_specific_config_directory_name); } $class_file_name = self::get_html_page_class_file_name(); if ($fh = fopen($class_file_name, 'w')) { fwrite($fh, $page_class_name . PHP_EOL); fclose($fh); } } }
public static function set_camel_case_root($camel_case_root, HaddockProjectOrganisation_ModuleDirectory $module_directory) { $validator = new HaddockProjectOrganisation_ModuleDirectoryCamelCaseRootValidator(); if ($validator->validate($camel_case_root)) { $module_directory->make_sure_config_directory_exists(); $config_directory_name = $module_directory->get_config_directory_name(); $haddock_project_organisation_config_directory_name = $config_directory_name . DIRECTORY_SEPARATOR . 'haddock-project-organisation'; if (!is_dir($haddock_project_organisation_config_directory_name)) { FileSystem_DirectoryHelper::mkdir_parents($haddock_project_organisation_config_directory_name); } $camel_case_root_file_name = self::get_camel_case_root_file_name($module_directory); if ($fh = fopen($camel_case_root_file_name, 'w')) { fwrite($fh, $camel_case_root . PHP_EOL); fclose($fh); } } }
public static function create_directory_class($new_directory_class_name, HaddockProjectOrganisation_ModuleDirectory $module_directory) { $classes_directory = $module_directory->get_classes_directory(); $directory_classes_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'file-system' . DIRECTORY_SEPARATOR . 'directories'; echo '$directory_classes_directory_name: ' . $directory_classes_directory_name . PHP_EOL; FileSystem_DirectoryHelper::mkdir_parents($directory_classes_directory_name); $directory_class_name = $module_directory->get_camel_case_root() . '_' . $new_directory_class_name . 'Directory'; echo '$directory_class_name: ' . $directory_class_name . PHP_EOL; $directory_class_file_name = $directory_classes_directory_name . DIRECTORY_SEPARATOR . $directory_class_name . '.inc.php'; echo '$directory_class_file_name: ' . $directory_class_file_name . PHP_EOL; if (is_file($directory_class_file_name)) { throw new ErrorHandling_SprintfException('\'%s\' already exists!', array($directory_class_file_name)); } else { $date = date('Y-m-d'); $copyright_holder = $module_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$directory_class_name} * * @copyright {$date}, {$copyright_holder} */ class \t{$directory_class_name} extends \tFileSystem_Directory { \t/* \t * Write code here. \t */ } ?> CNT; if ($fh = fopen($directory_class_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } }
public static function create_project_specific_html_page_class() { $project_specific_directory = HaddockProjectOrganisation_ProjectSpecificDirectoryHelper::get_project_specific_directory(); $project_specific_directory->make_sure_classes_directory_exists(); $classes_directory = $project_specific_directory->get_classes_directory(); $html_pages_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'html'; #echo '$html_pages_directory_name: ' . $html_pages_directory_name . PHP_EOL; FileSystem_DirectoryHelper::mkdir_parents($html_pages_directory_name); $project_specific_html_page_class_name = $project_specific_directory->get_camel_case_root() . '_' . 'HTMLPage'; #echo '$project_specific_html_page_class_name: ' . $project_specific_html_page_class_name . PHP_EOL; $project_specific_html_page_class_file_name = $html_pages_directory_name . DIRECTORY_SEPARATOR . $project_specific_html_page_class_name . '.inc.php'; #echo '$project_specific_html_page_class_file_name: ' . $project_specific_html_page_class_file_name . PHP_EOL; if (is_file($project_specific_html_page_class_file_name)) { throw new ErrorHandling_SprintfException('\'%s\' already exists!', array($project_specific_html_page_class_file_name)); } else { $date = date('Y-m-d'); $copyright_holder = $project_specific_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$project_specific_html_page_class_name} * * @copyright {$date}, {$copyright_holder} */ abstract class \t{$project_specific_html_page_class_name} extends \tPublicHTML_HTMLPage { } ?> CNT; if ($fh = fopen($project_specific_html_page_class_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } }
public function make_sure_config_directory_exists() { if (!$this->has_classes_directory()) { FileSystem_DirectoryHelper::mkdir_parents($this->get_config_directory_name()); } }
public static function create_html_pages() { /* * Find the project specific directory for the classes. */ $project_specific_directory = HaddockProjectOrganisation_ProjectSpecificDirectoryHelper::get_project_specific_directory(); $project_specific_directory->make_sure_classes_directory_exists(); $classes_directory = $project_specific_directory->get_classes_directory(); $html_pages_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'html'; FileSystem_DirectoryHelper::mkdir_parents($html_pages_directory_name); $project_specific_html_page_class_name = $project_specific_directory->get_camel_case_root() . '_' . 'HTMLPage'; /* * Create the abstract class for the user login pages. */ $project_specific_user_login_html_page_class_name = $project_specific_directory->get_camel_case_root() . '_' . 'UserLoginHtmlPage'; $project_specific_user_login_html_page_class_file_name = $html_pages_directory_name . DIRECTORY_SEPARATOR . $project_specific_user_login_html_page_class_name . '.inc.php'; if (is_file($project_specific_user_login_html_page_class_file_name)) { echo "'{$project_specific_user_login_html_page_class_file_name}' already exists!" . PHP_EOL; } else { $date = date('Y-m-d'); $copyright_holder = $project_specific_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$project_specific_user_login_html_page_class_name} * * @copyright {$date}, {$copyright_holder} */ abstract class \t{$project_specific_user_login_html_page_class_name} extends \t{$project_specific_html_page_class_name} { public function get_error_message_div() { return UserLogin_DisplayHelper::get_error_message_div(); } public function get_login_status_div() { return UserLogin_DisplayHelper::get_login_status_div(); } } ?> CNT; if ($fh = fopen($project_specific_user_login_html_page_class_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } /* * Create the registration page. */ $project_specific_registration_html_page_class_name = $project_specific_directory->get_camel_case_root() . '_' . 'UserLoginRegistrationHtmlPage'; $project_specific_registration_html_page_class_file_name = $html_pages_directory_name . DIRECTORY_SEPARATOR . $project_specific_registration_html_page_class_name . '.inc.php'; if (is_file($project_specific_registration_html_page_class_file_name)) { echo "'{$project_specific_registration_html_page_class_file_name}' already exists!" . PHP_EOL; } else { $date = date('Y-m-d'); $copyright_holder = $project_specific_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$project_specific_registration_html_page_class_name} * * @copyright {$date}, {$copyright_holder} */ class \t{$project_specific_registration_html_page_class_name} extends \t{$project_specific_user_login_html_page_class_name} { public function content() { \$div = new HTMLTags_Div(); \$div->append(\$this->get_error_message_div()); \$div->append(\$this->get_registration_div()); echo \$div->get_as_string(); } public function get_registration_div() { return UserLogin_DisplayHelper::get_registration_div(); } } ?> CNT; if ($fh = fopen($project_specific_registration_html_page_class_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } }
public static function initialise_delta_files_database() { Configuration_ConfigDirectoriesHelper::make_sure_instance_specific_config_directory_exists(); FileSystem_DirectoryHelper::mkdir_parents(self::get_delta_files_database_file_directory_name()); $delta_files_database = new SQLiteDatabase(self::get_delta_files_database_file_name()); $stmt = <<<SQL CREATE TABLE \tdelta_file_applications ( \t\tname TEXT NOT NULL UNIQUE, \t\tmd5 TEXT, \t\tapplied INTEGER \t) SQL; $delta_files_database->query($stmt); }
public function test_mkdir_parents_three_levels_deep() { $tld_dir_name = self::get_test_dir_name() . DIRECTORY_SEPARATOR . 'bing' . DIRECTORY_SEPARATOR . 'bang' . DIRECTORY_SEPARATOR . 'bong'; FileSystem_DirectoryHelper::mkdir_parents($tld_dir_name); return is_dir($tld_dir_name); }
public static function save_table_structure_in_directory(Database_Table $table, $table_specification_directory_name) { $debug = FALSE; #$debug = TRUE; $table_name = $table->get_name(); if ($debug) { echo '$table_name: ' . $table_name . PHP_EOL; } /* * Make sure that the dir exists. */ if (!is_dir($table_specification_directory_name)) { FileSystem_DirectoryHelper::mkdir_parents($table_specification_directory_name); } foreach ($db_table->get_fields() as $db_field) { $db_field_name = $db_field->get_name(); if ($debug) { echo '$db_field_name: ' . $db_field_name . PHP_EOL; } /* * Save the type. */ $db_field_type = $db_field->get_type(); if ($debug) { echo '$db_field_type: ' . $db_field_type . PHP_EOL; } $db_field_type_file_name = $table_specification_directory_name . DIRECTORY_SEPARATOR . $db_field_name . '.type'; if ($debug) { echo '$db_field_type_file_name: ' . $db_field_type_file_name . PHP_EOL; } if (!$debug) { if ($fh = fopen($db_field_type_file_name, 'w')) { fwrite($fh, $db_field_type . PHP_EOL); fclose($fh); } } /* * Save whether this field can be null or not */ $db_field_can_be_null = $db_field->can_be_null(); if ($debug) { echo '$db_field_can_be_null: ' . ($db_field_can_be_null ? 'YES' : 'NO') . PHP_EOL; } $db_field_can_be_null_file_name = $table_specification_directory_name . DIRECTORY_SEPARATOR . $db_field_name . '.can-be-null'; if ($debug) { echo '$db_field_can_be_null_file_name: ' . $db_field_can_be_null_file_name . PHP_EOL; } if (!$debug) { if ($fh = fopen($db_field_can_be_null_file_name, 'w')) { fwrite($fh, ($db_field_can_be_null ? 'YES' : 'NO') . PHP_EOL); fclose($fh); } } /* * Save the key */ $db_field_key = $db_field->get_key(); if (strlen($db_field_key) > 0) { if ($debug) { echo '$db_field_key: ' . $db_field_key . PHP_EOL; } $db_field_key_file_name = $table_specification_directory_name . DIRECTORY_SEPARATOR . $db_field_name . '.key'; if ($debug) { echo '$db_field_key_file_name: ' . $db_field_key_file_name . PHP_EOL; } if (!$debug) { if ($fh = fopen($db_field_key_file_name, 'w')) { fwrite($fh, $db_field_key . PHP_EOL); fclose($fh); } } } /* * Save the default */ $db_field_default = $db_field->get_default(); if (strlen($db_field_default) > 0) { if ($debug) { echo '$db_field_default: ' . $db_field_default . PHP_EOL; } $db_field_default_file_name = $table_specification_directory_name . DIRECTORY_SEPARATOR . $db_field_name . '.default'; if ($debug) { echo '$db_field_default_file_name: ' . $db_field_default_file_name . PHP_EOL; } if (!$debug) { if ($fh = fopen($db_field_default_file_name, 'w')) { fwrite($fh, $db_field_default . PHP_EOL); fclose($fh); } } } /* * Save any extra info. */ $db_field_extra = $db_field->get_extra(); if (strlen($db_field_extra) > 0) { if ($debug) { echo '$db_field_extra: ' . $db_field_extra . PHP_EOL; } $db_field_extra_file_name = $table_specification_directory_name . DIRECTORY_SEPARATOR . $db_field_name . '.extra'; if ($debug) { echo '$db_field_extra_file_name: ' . $db_field_extra_file_name . PHP_EOL; } if (!$debug) { if ($fh = fopen($db_field_extra_file_name, 'w')) { fwrite($fh, $db_field_extra . PHP_EOL); fclose($fh); } } } } #/* # * Save the indexes. # */ # #$dbh = DB::m(); # #$query = "SHOW INDEX FROM $table_name"; # #$result = mysql_query($query, $dbh); # #while ($row = mysql_fetch_assoc($result)) { # print_r($row); # # $index_file_name # = $table_specification_directory_name # . DIRECTORY_SEPARATOR . $row['Key_name'] . '.index'; # echo '$index_file_name: ' . $index_file_name . PHP_EOL; # # if ($fh = fopen($index_file_name, 'w')) { # foreach ( # explode(' ', 'Non_unique Column_name') # as # $key # ) { # fwrite( # $fh, # $key . ': ' . $row[$key] . PHP_EOL # ); # } # # fclose($fh); # } #} }
public static function create_unit_tests_class($new_unit_tests_class_name, HaddockProjectOrganisation_ModuleDirectory $module_directory) { $classes_directory = $module_directory->get_classes_directory(); $unit_tests_directory_name = $classes_directory->get_name() . DIRECTORY_SEPARATOR . 'unit-tests'; #echo '$unit_tests_directory_name: ' . $unit_tests_directory_name . PHP_EOL; FileSystem_DirectoryHelper::mkdir_parents($unit_tests_directory_name); $unit_tests_class_name = $module_directory->get_camel_case_root() . '_' . $new_unit_tests_class_name . 'Tests'; #echo '$unit_tests_class_name: ' . $unit_tests_class_name . PHP_EOL; $unit_tests_class_file_name = $unit_tests_directory_name . DIRECTORY_SEPARATOR . $unit_tests_class_name . '.inc.php'; #echo '$unit_tests_class_file_name: ' . $unit_tests_class_file_name . PHP_EOL; if (is_file($unit_tests_class_file_name)) { throw new ErrorHandling_SprintfException('\'%s\' already exists!', array($unit_tests_class_file_name)); } else { $date = date('Y-m-d'); $copyright_holder = $module_directory->get_copyright_holder(); $file_contents = <<<CNT <?php /** * {$unit_tests_class_name} * * @copyright {$date}, {$copyright_holder} */ class \t{$unit_tests_class_name} extends \tUnitTests_UnitTests { \tpublic static function \t\tset_up() \t{ \t\t/* \t\t * Prepare the environment for each test in this class. \t\t */ \t} \t \tpublic static function \t\ttear_down() \t{ \t\t/* \t\t * Return the environment to a pristine state after \t\t * each test in this class. \t\t */ \t} \t \t/* \t * ---------------------------------------- \t * The tests. \t * ---------------------------------------- \t */ \t \t/* \t * Write public static test functions here. \t */ } ?> CNT; if ($fh = fopen($unit_tests_class_file_name, 'w')) { fwrite($fh, $file_contents); fclose($fh); HaddockProjectOrganisation_AutoloadFilesHelper::refresh_autoload_file(); } } }