environment('testing'), 503, 'Extensão de conversão limitada a QA.'); $connection = DB::connection(); abort_unless(($connection->getDriverName() === 'sqlite' && $connection->getDatabaseName() === ':memory:') || ($connection->getDriverName() === 'pgsql' && preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $connection->getDatabaseName())), 503, 'Base QA isolada obrigatória.'); $root = base_path('packages/inventory-write/development'); $pin = '90cf565537e7fd48eb54a87bcfd6d585cf53239f075764910047838b3b8b4c38'; $files[] = 'src/QuantityConversion.php'; } $bytes = is_file($root.'/manifest.json') ? file_get_contents($root.'/manifest.json') : false; if (! is_string($bytes) || ! hash_equals($pin, hash('sha256', $bytes))) { throw new \LogicException('Pacote de recepção incompatível; não executar outro escritor.'); } $manifest = json_decode($bytes, true, 512, JSON_THROW_ON_ERROR); foreach ($files as $file) { $actual = is_file($root.'/'.$file) ? hash_file('sha256', $root.'/'.$file) : false; if (! is_string($actual) || ! hash_equals($manifest['files'][$file] ?? '', $actual)) { throw new \LogicException('Pacote de recepção alterado.'); } } if (class_exists(ReceiptMovementWriter::class, false)) { $loaded = (new \ReflectionClass(ReceiptMovementWriter::class))->getFileName(); if (! is_string($loaded) || realpath($loaded) !== realpath($root.'/src/ReceiptMovementWriter.php')) { throw new \LogicException('Escritor já carregado de outra versão; use um kernel QA separado.'); } } require_once $root.'/bootstrap.php'; } public function for(User $actor): ReceiptMovementWriter { $this->load(); $schema = match (DB::connection()->getDriverName()) { 'pgsql' => 'public','sqlite' => 'main','mysql','mariadb' => DB::connection()->getDatabaseName(), default => throw new \LogicException('Driver de inventário não suportado.'), }; return new ReceiptMovementWriter(DB::connection(), $schema, (int) $actor->tenant_id, (int) $actor->id, function () use ($actor) { app(CurrentActor::class)->lock($actor, [PurchasingRole::Warehouse]); }); } }