refactor: rename lib/ to core/ for clearer core-module separation
Rename the top-level lib/ directory to core/ so the project root immediately communicates which code is core platform and which lives in modules/. PHP namespaces (MintyPHP\*) are unchanged — only the Composer PSR-4 path mapping moves from lib/ to core/. Module-internal lib/ directories (modules/*/lib/) are untouched. Updated across the full stack: - composer.json PSR-4 mapping - bootstrap entry points (web/index.php, bin/*, tests/bootstrap.php) - tooling configs (phpstan.neon, phpunit.xml, php-cs-fixer) - 26 architecture contract tests - enforcement-policy, guard-catalog, quality-gates - all documentation (CLAUDE.md, README, 25 docs/, .agents/skills/) - bin/qa-extended.sh search paths - .claude/settings.local.json permission paths Workflow: .agents/runs/CORE-LIB-RENAME-001/ (Analyst → Planner → Executor → Code Review (4 findings fixed) → Security Review → Acceptance Test → Finalizer) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Repository\CustomField;
|
||||
|
||||
use MintyPHP\DB;
|
||||
|
||||
/** Retrieves selectable options for tenant-scoped custom field definitions. */
|
||||
class TenantCustomFieldOptionRepository
|
||||
{
|
||||
private static function unwrapList($rows): array
|
||||
{
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$item = $row['tenant_custom_field_options'] ?? null;
|
||||
if (is_array($item)) {
|
||||
$list[] = $item;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function listByDefinitionIds(array $definitionIds, bool $onlyActive = true): array
|
||||
{
|
||||
$definitionIds = array_values(array_unique(array_map('intval', $definitionIds)));
|
||||
$definitionIds = array_values(array_filter($definitionIds, static fn ($id) => $id > 0));
|
||||
if (!$definitionIds) {
|
||||
return [];
|
||||
}
|
||||
$query = 'select id, definition_id, option_key, label, active, sort_order, created, modified ' .
|
||||
'from tenant_custom_field_options where definition_id in (???)';
|
||||
$params = [$definitionIds];
|
||||
if ($onlyActive) {
|
||||
$query .= ' and active = 1';
|
||||
}
|
||||
$query .= ' order by definition_id asc, sort_order asc, label asc, id asc';
|
||||
return self::unwrapList(call_user_func_array(['MintyPHP\\DB', 'select'], array_merge([$query], $params)));
|
||||
}
|
||||
|
||||
public static function replaceForDefinition(int $definitionId, array $options): bool
|
||||
{
|
||||
if ($definitionId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$existing = self::listByDefinitionIds([$definitionId], false);
|
||||
$existingByKey = [];
|
||||
foreach ($existing as $row) {
|
||||
$key = (string) ($row['option_key'] ?? '');
|
||||
if ($key !== '') {
|
||||
$existingByKey[$key] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$keepIds = [];
|
||||
foreach ($options as $option) {
|
||||
if (!is_array($option)) {
|
||||
continue;
|
||||
}
|
||||
$optionKey = trim((string) ($option['option_key'] ?? ''));
|
||||
$label = trim((string) ($option['label'] ?? ''));
|
||||
if ($optionKey === '' || $label === '') {
|
||||
continue;
|
||||
}
|
||||
$active = !empty($option['active']) ? 1 : 0;
|
||||
$sortOrder = (int) ($option['sort_order'] ?? 100);
|
||||
|
||||
if (isset($existingByKey[$optionKey]['id'])) {
|
||||
$optionId = (int) $existingByKey[$optionKey]['id'];
|
||||
$keepIds[] = $optionId;
|
||||
$updated = DB::update(
|
||||
'update tenant_custom_field_options set label = ?, active = ?, sort_order = ? where id = ?',
|
||||
$label,
|
||||
(string) $active,
|
||||
(string) $sortOrder,
|
||||
(string) $optionId
|
||||
);
|
||||
if ($updated === false) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$insertId = DB::insert(
|
||||
'insert into tenant_custom_field_options (definition_id, option_key, label, active, sort_order, created) values (?,?,?,?,?,NOW())',
|
||||
(string) $definitionId,
|
||||
$optionKey,
|
||||
$label,
|
||||
(string) $active,
|
||||
(string) $sortOrder
|
||||
);
|
||||
if ($insertId === false) {
|
||||
return false;
|
||||
}
|
||||
if ($insertId) {
|
||||
$keepIds[] = (int) $insertId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$keepIds) {
|
||||
$deleted = DB::delete('delete from tenant_custom_field_options where definition_id = ?', (string) $definitionId);
|
||||
if ($deleted === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$deleted = DB::delete(
|
||||
'delete from tenant_custom_field_options where definition_id = ? and id not in (???)',
|
||||
(string) $definitionId,
|
||||
$keepIds
|
||||
);
|
||||
if ($deleted === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteByDefinitionId(int $definitionId): bool
|
||||
{
|
||||
if ($definitionId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$result = DB::delete('delete from tenant_custom_field_options where definition_id = ?', (string) $definitionId);
|
||||
return $result !== false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user