if (!file_exists(REPOSITORY_PATH . $className . '.php')) { //$entity_name = readline($className . ": "); $entity_name = readline_predefined($className . ": ", Inflector::singularize($className)); newEntity($cols, $entity_name); } else { $repository = file_get_contents(REPOSITORY_PATH . $className . '.php'); preg_match('/(?<=@entity \\\\).*/', $repository, $matches); if (!$matches) { continue; } $matches = explode("\\", $matches[0]); $entity_name = end($matches); if (file_exists(ENTITY_PATH . $entity_name . '.php')) { editEntity($cols, $entity_name); } else { newEntity($cols, $entity_name); } } } if (!file_exists(REPOSITORY_PATH . $className . '.php')) { // Repozitář $properties = " * @table {$name}\n * @entity \\" . NS . 'Model\\Entity\\' . $entity_name; $buffer = "namespace " . NS . "Model\\Repository;\n\n/**\n{$properties}\n */\nfinal class {$className} extends Base\n{\n\n}"; file_put_contents(REPOSITORY_PATH . $className . '.php', "<?php\n\n{$buffer}\n"); } } echo "\r\n"; echo "\r\n"; /** * Vytvori novou entitu * @param $className
function generateEntity($className, $cols) { if (!file_exists(REPOSITORY_PATH . $className . '.php')) { $entity_name = readline_predefined(" Entity name for repo '" . $className . "': ", Inflector::singularize($className)); newEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' generated"); } else { $repository = file_get_contents(REPOSITORY_PATH . $className . '.php'); preg_match('/(?<=@entity \\\\).*/', $repository, $matches); if (!$matches) { return null; } $matches = explode("\\", $matches[0]); $entity_name = end($matches); if (file_exists(ENTITY_PATH . $entity_name . '.php')) { editEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' updated"); } else { newEntity($cols, $entity_name); drawRow("Entity '{$entity_name}' generated"); } } return $entity_name; }