Compare commits

..

No commits in common. "5ecc9ac3d7e20d756137f8e784a618bce366c7ff" and "8cab7b6064f2e512298f9b25e7dfdcc27d011b06" have entirely different histories.

10 changed files with 36 additions and 79 deletions

1
.idea/nulib-base.iml generated
View File

@ -4,7 +4,6 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/php/src" isTestSource="false" packagePrefix="nulib\" /> <sourceFolder url="file://$MODULE_DIR$/php/src" isTestSource="false" packagePrefix="nulib\" />
<sourceFolder url="file://$MODULE_DIR$/php/tests" isTestSource="true" packagePrefix="nulib\" /> <sourceFolder url="file://$MODULE_DIR$/php/tests" isTestSource="true" packagePrefix="nulib\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/php/vendor" /> <excludeFolder url="file://$MODULE_DIR$/php/vendor" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpTestFrameworkVersionCache">
<tools_cache>
<tool tool_name="PHPUnit">
<cache>
<versions>
<info id="Local/php/vendor/autoload.php" version="9.6.23" />
</versions>
</cache>
</tool>
</tools_cache>
</component>
</project>

12
.idea/php.xml generated
View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="MessDetector">
<phpmd_settings>
<phpmd_by_interpreter asDefaultInterpreter="true" interpreter_id="846389f7-9fb5-4173-a868-1dc6b8fbb3fa" timeout="30000" />
</phpmd_settings>
</component>
<component name="MessDetectorOptionsConfiguration"> <component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>
@ -15,11 +10,6 @@
<option name="highlightLevel" value="WARNING" /> <option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>
<component name="PhpCodeSniffer">
<phpcs_settings>
<phpcs_by_interpreter asDefaultInterpreter="true" interpreter_id="846389f7-9fb5-4173-a868-1dc6b8fbb3fa" timeout="30000" />
</phpcs_settings>
</component>
<component name="PhpIncludePathManager"> <component name="PhpIncludePathManager">
<include_path> <include_path>
<path value="$PROJECT_DIR$/php/vendor/symfony/polyfill-ctype" /> <path value="$PROJECT_DIR$/php/vendor/symfony/polyfill-ctype" />
@ -65,7 +55,7 @@
</component> </component>
<component name="PhpUnit"> <component name="PhpUnit">
<phpunit_settings> <phpunit_settings>
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/php/vendor/autoload.php" phpunit_phar_path="" /> <PhpUnitSettings configuration_file_path="$PROJECT_DIR$/php/vendor/sebastian/object-enumerator/phpunit.xml" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" use_configuration_file="true" />
</phpunit_settings> </phpunit_settings>
</component> </component>
<component name="PsalmOptionsConfiguration"> <component name="PsalmOptionsConfiguration">

10
.idea/phpunit.xml generated
View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PHPUnit">
<option name="directories">
<list>
<option value="$PROJECT_DIR$/tests" />
</list>
</option>
</component>
</project>

View File

@ -32,29 +32,19 @@ abstract class CapacitorStorage {
return $channel; return $channel;
} }
const PRIMARY_KEY_DEFINITION = [ /** DOIT être défini dans les classes dérivées */
"id_" => "genserial", const PRIMARY_KEY_DEFINITION = null;
];
# les définitions sont par défaut pour MariaDB/MySQL
const SERDATA_DEFINITION = "mediumtext"; const SERDATA_DEFINITION = "mediumtext";
const SERSUM_DEFINITION = "varchar(40)"; const SERSUM_DEFINITION = "varchar(40)";
const SERTS_DEFINITION = "datetime"; const SERTS_DEFINITION = "datetime";
const GENSERIAL_DEFINITION = "integer primary key autoincrement";
const GENLIC_DEFINITION = "varchar(80)";
const GENLIB_DEFINITION = "varchar(255)";
const GENTEXT_DEFINITION = "mediumtext";
protected static function gencol($def): string { protected static function sercol($def): string {
if (!is_string($def)) $def = strval($def); if (!is_string($def)) $def = strval($def);
switch ($def) { switch ($def) {
case "serdata": $def = static::SERDATA_DEFINITION; break; case "serdata": $def = static::SERDATA_DEFINITION; break;
case "sersum": $def = static::SERSUM_DEFINITION; break; case "sersum": $def = static::SERSUM_DEFINITION; break;
case "serts": $def = static::SERTS_DEFINITION; break; case "serts": $def = static::SERTS_DEFINITION; break;
case "genserial": $def = static::GENSERIAL_DEFINITION; break;
case "genlic": $def = static::GENLIC_DEFINITION; break;
case "genlib": $def = static::GENLIB_DEFINITION; break;
case "gentext": $def = static::GENTEXT_DEFINITION; break;
} }
return $def; return $def;
} }
@ -91,7 +81,7 @@ abstract class CapacitorStorage {
$mindex++; $mindex++;
} else { } else {
if ($mdef) { if ($mdef) {
$definitions[$mcol] = self::gencol($mdef); $definitions[$mcol] = self::sercol($mdef);
} else { } else {
unset($definitions[$mcol]); unset($definitions[$mcol]);
} }
@ -102,7 +92,7 @@ abstract class CapacitorStorage {
$constraints[] = $def; $constraints[] = $def;
} }
} else { } else {
$definitions[$col] = self::gencol($def); $definitions[$col] = self::sercol($def);
} }
} }
return cl::merge($definitions, $constraints); return cl::merge($definitions, $constraints);

View File

@ -19,6 +19,10 @@ class MysqlStorage extends CapacitorStorage {
return $this->db; return $this->db;
} }
const PRIMARY_KEY_DEFINITION = [
"id_" => "integer primary key auto_increment",
];
protected function tableExists(string $tableName): bool { protected function tableExists(string $tableName): bool {
$db = $this->db; $db = $this->db;
$found = $db->get([ $found = $db->get([

View File

@ -9,8 +9,6 @@ class PgsqlStorage extends CapacitorStorage {
const SERDATA_DEFINITION = "text"; const SERDATA_DEFINITION = "text";
const SERSUM_DEFINITION = "varchar(40)"; const SERSUM_DEFINITION = "varchar(40)";
const SERTS_DEFINITION = "timestamp"; const SERTS_DEFINITION = "timestamp";
const GENSERIAL_DEFINITION = "serial primary key";
const GENTEXT_DEFINITION = "text";
function __construct($pgsql) { function __construct($pgsql) {
$this->db = Pgsql::with($pgsql); $this->db = Pgsql::with($pgsql);
@ -22,6 +20,10 @@ class PgsqlStorage extends CapacitorStorage {
return $this->db; return $this->db;
} }
const PRIMARY_KEY_DEFINITION = [
"id_" => "serial primary key",
];
protected function tableExists(string $tableName): bool { protected function tableExists(string $tableName): bool {
if (($index = strpos($tableName, ".")) !== false) { if (($index = strpos($tableName, ".")) !== false) {
$schemaName = substr($tableName, 0, $index); $schemaName = substr($tableName, 0, $index);

View File

@ -19,6 +19,10 @@ class SqliteStorage extends CapacitorStorage {
return $this->db; return $this->db;
} }
const PRIMARY_KEY_DEFINITION = [
"id_" => "integer primary key autoincrement",
];
protected function tableExists(string $tableName): bool { protected function tableExists(string $tableName): bool {
$found = $this->db->get([ $found = $this->db->get([
# depuis la version 3.33.0 le nom officiel de la table est sqlite_schema, # depuis la version 3.33.0 le nom officiel de la table est sqlite_schema,

View File

@ -7,12 +7,6 @@ use nulib\db\Capacitor;
use nulib\db\CapacitorChannel; use nulib\db\CapacitorChannel;
class SqliteStorageTest extends TestCase { class SqliteStorageTest extends TestCase {
static function Txx(...$values): void {
foreach ($values as $value) {
var_export($value);
}
}
function _testChargeStrings(SqliteStorage $storage, ?string $channel) { function _testChargeStrings(SqliteStorage $storage, ?string $channel) {
$storage->reset($channel); $storage->reset($channel);
$storage->charge($channel, "first"); $storage->charge($channel, "first");
@ -84,7 +78,7 @@ class SqliteStorageTest extends TestCase {
$capacitor->each(["age" => [">", 10]], $setDone, ["++"]); $capacitor->each(["age" => [">", 10]], $setDone, ["++"]);
$capacitor->each(["done" => 0], $setDone, null); $capacitor->each(["done" => 0], $setDone, null);
self::Txx(cl::all($capacitor->discharge(false))); Txx(cl::all($capacitor->discharge(false)));
$capacitor->close(); $capacitor->close();
self::assertTrue(true); self::assertTrue(true);
} }
@ -139,16 +133,16 @@ class SqliteStorageTest extends TestCase {
$capacitor->charge(["a" => null, "b" => null]); $capacitor->charge(["a" => null, "b" => null]);
$capacitor->charge(["a" => "first", "b" => "second"]); $capacitor->charge(["a" => "first", "b" => "second"]);
self::Txx("=== all"); Txx("=== all");
/** @var Sqlite $sqlite */ /** @var Sqlite $sqlite */
$sqlite = $capacitor->getStorage()->db(); $sqlite = $capacitor->getStorage()->db();
self::Txx(cl::all($sqlite->all([ Txx(cl::all($sqlite->all([
"select", "select",
"from" => $capacitor->getChannel()->getTableName(), "from" => $capacitor->getChannel()->getTableName(),
]))); ])));
self::Txx("=== each"); Txx("=== each");
$capacitor->each(null, function ($item, $values) { $capacitor->each(null, function ($item, $values) {
self::Txx($values); Txx($values);
}); });
$capacitor->close(); $capacitor->close();

View File

@ -41,9 +41,9 @@ p == 1 {
} }
declare -A PHPWRAPPER_DESTDIRS=( declare -A PHPWRAPPER_DESTDIRS=(
[_bg_launcher.php]=@@SBIN@@ [_bg_launcher.php]=sbin
[.launcher.php]=@@CLI@@ [.launcher.php]=cli
[_wrapper.sh]=@@CLI@@ [_wrapper.sh]=cli
) )
declare -A PHPWRAPPER_MODES=( declare -A PHPWRAPPER_MODES=(
[_bg_launcher.php]=+x [_bg_launcher.php]=+x
@ -156,20 +156,20 @@ if [ -n "$projdir" ]; then
' '
fi fi
sbin_path=sbin sbin_dest=sbin
cli_path=cli_config cli_dest=cli_config
if [ "$install_phpwrappers" == auto ]; then if [ "$install_phpwrappers" == auto ]; then
if [ ! -f "$PROJDIR/$COMPOSERDIR/composer.json" ]; then if [ ! -f "$PROJDIR/$COMPOSERDIR/composer.json" ]; then
# ce doit être un projet PHP # ce doit être un projet PHP
install_phpwrappers= install_phpwrappers=
elif [ -d "$projdir/cli_config" ]; then elif [ -d "$projdir/cli_config" ]; then
install_phpwrappers=1 install_phpwrappers=1
sbin_path=sbin sbin_dest=sbin
cli_path=cli_config cli_dest=cli_config
elif [ -d "$projdir/_cli" ]; then elif [ -d "$projdir/_cli" ]; then
install_phpwrappers=1 install_phpwrappers=1
sbin_path=sbin sbin_dest=sbin
cli_path=_cli cli_dest=_cli
else else
install_phpwrappers= install_phpwrappers=
fi fi
@ -184,17 +184,15 @@ if [ -n "$projdir" ]; then
mode="${PHPWRAPPER_MODES[$destname]}" mode="${PHPWRAPPER_MODES[$destname]}"
case "$destdir" in case "$destdir" in
@@SBIN@@) destdir="$PROJDIR/$sbin_path";; sbin) destdir="$PROJDIR/$sbin_dest";;
@@CLI@@) destdir="$PROJDIR/$cli_path";; cli) destdir="$PROJDIR/$cli_dest";;
*) destdir="$PROJDIR/$destdir";; *) destdir="$PROJDIR/$destdir";;
esac esac
estep "$(relpath "$destdir/$destname")" estep "$(relpath "$destdir/$destname")"
mkdir -p "$destdir" mkdir -p "$destdir"
tail -n+4 "$MYDIR/$phpwrapper" | sed " tail -n+4 "$MYDIR/$phpwrapper" |
s|/@@SBIN@@/|/$sbin_path/| sed "s|/@@CLI@@/|/$cli_dest/|" >"$destdir/$destname"
s|/@@CLI@@/|/$cli_path/|
" >"$destdir/$destname"
[ -n "$mode" ] && chmod "$mode" "$destdir/$destname" [ -n "$mode" ] && chmod "$mode" "$destdir/$destname"
done done
fi fi