Skip to content

Commit

Permalink
refactor(builder): refactor from zephir.
Browse files Browse the repository at this point in the history
  • Loading branch information
noone-silent committed Jul 30, 2024
1 parent efba703 commit 81e5a0a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 38 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DATA_MONGODB_NAME="phalcon"
DATA_REDIS_HOST="redis"
DATA_REDIS_PORT=6379
DATA_REDIS_NAME="0"
DATA_REDIS_PASS="bitnami"

# SQLite
DATA_SQLITE_NAME="tests/_data/phalcon_test.sqlite"
Expand Down
36 changes: 16 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@ services:
hostname: phalcon-83
build: resources/docker/8.3
working_dir: /srv
links:
- mysql
- postgres
volumes:
- .:/srv

phalcon-8.3:
container_name: phalcon-8.3
hostname: phalcon-83
build: docker/8.3
working_dir: /srv
links:
- mysql
- postgres
volumes:
- .:/srv
extra_hosts:
- "host.docker.internal:host-gateway"

mysql:
container_name: phalcon-mysql
Expand All @@ -40,6 +28,8 @@ services:
- MYSQL_USER=${DATA_MYSQL_USER}
- MYSQL_DATABASE=${DATA_MYSQL_NAME}
- MYSQL_PASSWORD=${DATA_MYSQL_PASS}
extra_hosts:
- "host.docker.internal:host-gateway"

postgres:
container_name: phalcon-postgres
Expand All @@ -48,6 +38,8 @@ services:
- POSTGRES_PASSWORD=${DATA_POSTGRES_PASS}
- POSTGRES_USER=${DATA_POSTGRES_USER}
- POSTGRES_DB=${DATA_POSTGRES_NAME}
extra_hosts:
- "host.docker.internal:host-gateway"

mongodb:
container_name: phalcon-mongodb
Expand All @@ -56,6 +48,8 @@ services:
- MONGO_INITDB_ROOT_USERNAME=${DATA_MONGODB_USER}
- MONGO_INITDB_ROOT_PASSWORD=${DATA_MONGODB_PASS}
- MONGO_INITDB_DATABASE=${DATA_MONGODB_NAME}
extra_hosts:
- "host.docker.internal:host-gateway"

redis:
container_name: phalcon-redis
Expand All @@ -67,7 +61,7 @@ services:
container_name: phalcon-redis-node-0
image: docker.io/bitnami/redis-cluster:7.2
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -76,7 +70,7 @@ services:
container_name: phalcon-redis-node-1
image: docker.io/bitnami/redis-cluster:7.2
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -85,7 +79,7 @@ services:
container_name: phalcon-redis-node-2
image: docker.io/bitnami/redis-cluster:7.2
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -94,7 +88,7 @@ services:
container_name: phalcon-redis-node-3
image: docker.io/bitnami/redis-cluster:7.2
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -103,7 +97,7 @@ services:
container_name: phalcon-redis-node-4
image: docker.io/bitnami/redis-cluster:7.2
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
extra_hosts:
- "host.docker.internal:host-gateway"
Expand All @@ -118,7 +112,7 @@ services:
- redis-node-3
- redis-node-4
environment:
- 'REDIS_PASSWORD=bitnami'
- REDIS_PASSWORD=${DATA_REDIS_PASS}
- 'REDISCLI_AUTH=bitnami'
- 'REDIS_CLUSTER_REPLICAS=1'
- 'REDIS_NODES=phalcon-redis-node-0 phalcon-redis-node-1 phalcon-redis-node-2 phalcon-redis-node-3 phalcon-redis-node-4 phalcon-redis-node-5'
Expand All @@ -129,3 +123,5 @@ services:
memcached:
container_name: phalcon-memcached
image: memcached:1.6-alpine
extra_hosts:
- "host.docker.internal:host-gateway"
19 changes: 19 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="vendor/autoload.php"
cacheDirectory=".local/cache"
findUnusedBaselineEntry="true"
findUnusedCode="true"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
4 changes: 4 additions & 0 deletions src/Mvc/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Mvc\Model\CriteriaInterface;
use Phalcon\Mvc\Model\Exception;
use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model\ManagerInterface;
use Phalcon\Mvc\Model\MetaDataInterface;
use Phalcon\Mvc\Model\QueryInterface;
Expand Down Expand Up @@ -6298,6 +6299,7 @@ private static function getPreparedQuery(
mixed $limit = null
): QueryInterface {
$container = Di::getDefault();
/** @var Manager $manager */
$manager = $container->getShared("modelsManager");

/**
Expand All @@ -6309,6 +6311,8 @@ private static function getPreparedQuery(

if ($limit != null) {
$builder->limit($limit);
} elseif (isset($params['limit'])) {
$builder->limit($params['limit'], $params['offset'] ?? null);
}

$query = $builder->getQuery();
Expand Down
10 changes: 5 additions & 5 deletions src/Mvc/Model/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class Builder implements BuilderInterface, InjectionAwareInterface
protected array | string | null $columns = null;

/**
* @var string|null
* @var array|string|null
*/
protected string | null $conditions = null;
protected array | string | null $conditions = null;

/**
* @var DiInterface|null
Expand Down Expand Up @@ -113,7 +113,7 @@ class Builder implements BuilderInterface, InjectionAwareInterface
/**
* @var array|int|string
*/
protected array | int | string $limit;
protected array | int | string $limit = 0;

/**
* @var array|string|null
Expand All @@ -128,7 +128,7 @@ class Builder implements BuilderInterface, InjectionAwareInterface
/**
* @var array|string
*/
protected array | string $order;
protected array | string $order = [];

/**
* @var bool
Expand All @@ -147,7 +147,7 @@ public function __construct(array | string | null $params = null, DiInterface |
/**
* Process conditions
*/
$this->conditions = $params[0] ?? $params['conditions'];
$this->conditions = $params[0] ?? $params['conditions'] ?? [];
}

if (is_array($this->conditions)) {
Expand Down
26 changes: 13 additions & 13 deletions tests/_data/fixtures/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Class AbstractMigration
*
* @property PDO $connection
* @property PDO $connection
* @property string $table
*/
abstract class AbstractMigration
Expand Down Expand Up @@ -92,21 +92,21 @@ public function clear(): int

$driver = $this->getDriverName();

// if ($driver === 'mysql') {
// return $this->connection->exec(
// 'truncate table ' . $this->table . ';'
// );
// }
//
// if ($driver === 'sqlite') {
if ($driver === 'mysql') {
return $this->connection->exec(
'TRUNCATE TABLE ' . $this->table . ';'
);
}

if ($driver === 'sqlite') {
return $this->connection->exec(
'delete from ' . $this->table . ';'
);
// }
//
// return $this->connection->exec(
// 'truncate table ' . $this->table . ' cascade;'
// );
}

return $this->connection->exec(
'truncate table ' . $this->table . ' cascade;'
);
}

/**
Expand Down

0 comments on commit 81e5a0a

Please sign in to comment.