Skip to content

Commit

Permalink
Updated Library Namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
alphasoft-fr committed Sep 6, 2023
1 parent 11bfc9f commit 2705c00
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 59 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To get started with ASLinkORM , you need to follow these steps:
1. **Initialize the DoctrineManager:** In your application's entry point, initialize the `DoctrineManager` with your database configuration. Make sure to adjust the configuration according to your database setup.

```php
use AlphaSoft\Sql\DoctrineManager;
use AlphaSoft\AsLinkOrm\DoctrineManager;

$config = [
'url' => 'mysql://username:password@localhost/db_name',
Expand All @@ -50,7 +50,7 @@ $config = [
2. **Create Repositories:** Create repository classes for your models by extending the `Repository` base class. Define the table name, model name, and selectable fields.

```php
use AlphaSoft\Sql\Repository\Repository;
use AlphaSoft\AsLinkOrm\Repository\Repository;

class UserRepository extends Repository
{
Expand All @@ -71,19 +71,19 @@ class UserRepository extends Repository
3. **Create Models:** Create model classes by extending the `HasEntity` base class. Define relationships and any custom methods you need.

```php
use AlphaSoft\Sql\Relation\HasEntity;
use AlphaSoft\AsLinkOrm\Relation\HasEntity;

class User extends HasEntity
{
static protected function columnsMapping(): array
{
return [
new \AlphaSoft\Sql\Mapping\PrimaryKeyColumn('id'),
new \AlphaSoft\Sql\Mapping\Column('firstname'),
new \AlphaSoft\Sql\Mapping\Column('lastname'),
new \AlphaSoft\Sql\Mapping\Column('email'),
new \AlphaSoft\Sql\Mapping\Column('password'),
new \AlphaSoft\Sql\Mapping\Column('isActive', false, 'is_active'),
new \AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn('id'),
new \AlphaSoft\AsLinkOrm\Mapping\Column('firstname'),
new \AlphaSoft\AsLinkOrm\Mapping\Column('lastname'),
new \AlphaSoft\AsLinkOrm\Mapping\Column('email'),
new \AlphaSoft\AsLinkOrm\Mapping\Column('password'),
new \AlphaSoft\AsLinkOrm\Mapping\Column('isActive', false, 'is_active'),
];
}

Expand Down Expand Up @@ -239,7 +239,7 @@ The `HasEntity` class offers two methods, `hasOne` and `hasMany`, which facilita
The `hasOne` method establishes a one-to-one relationship between the current model and another related model. Here's an example of how you might use it:

```php
use AlphaSoft\Sql\Relation\HasEntity;
use AlphaSoft\AsLinkOrm\Entity\HasEntity;

class User extends HasEntity
{
Expand All @@ -259,7 +259,7 @@ In this scenario, the `getProfile` method sets up a one-to-one relationship betw
The `hasMany` method establishes a one-to-many relationship between the current model and another related model. Consider this example:

```php
use AlphaSoft\Sql\Relation\HasEntity;
use AlphaSoft\AsLinkOrm\Entity\HasEntity;

class User extends HasEntity
{
Expand Down Expand Up @@ -307,7 +307,7 @@ ASLinkORM provides the ability to define column mappings for your models, giving
The `Column` object is used within the `columnsMapping()` method to define how model attributes correspond to database columns. It allows you to specify a default value and an optional database column name if it differs from the attribute name in the model.

```php
use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\AsLinkOrm\Mapping\Column;

$column1 = new Column('firstname'); // Basic usage, no specific column name specified
$column2 = new Column('lastname', 'Doe'); // Specifying a default value
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
],
"autoload": {
"psr-4": {
"AlphaSoft\\Sql\\": "src",
"Test\\AlphaSoft\\Sql\\": "tests"
"AlphaSoft\\AsLinkOrm\\": "src",
"Test\\AlphaSoft\\AsLinkOrm\\": "tests"
}
},
"require": {
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/ColumnCache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AlphaSoft\Sql\Cache;
namespace AlphaSoft\AsLinkOrm\Cache;

use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\AsLinkOrm\Mapping\Column;

final class ColumnCache
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/PrimaryKeyColumnCache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AlphaSoft\Sql\Cache;
namespace AlphaSoft\AsLinkOrm\Cache;

use AlphaSoft\Sql\Mapping\PrimaryKeyColumn;
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn;

final class PrimaryKeyColumnCache
{
Expand Down
2 changes: 1 addition & 1 deletion src/ConstructPdoDsn.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace AlphaSoft\Sql;
namespace AlphaSoft\AsLinkOrm;

final class ConstructPdoDsn
{
Expand Down
4 changes: 2 additions & 2 deletions src/DoctrineManager.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AlphaSoft\Sql;
namespace AlphaSoft\AsLinkOrm;

use AlphaSoft\Sql\Repository\Repository;
use AlphaSoft\AsLinkOrm\Repository\Repository;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/CustomDriver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace AlphaSoft\Sql\Driver;
namespace AlphaSoft\AsLinkOrm\Driver;

use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\PDO\Connection;
Expand Down
12 changes: 6 additions & 6 deletions src/Relation/HasEntity.php → src/Entity/HasEntity.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace AlphaSoft\Sql\Relation;
namespace AlphaSoft\AsLinkOrm\Entity;

use AlphaSoft\DataModel\Model;
use AlphaSoft\Sql\Cache\ColumnCache;
use AlphaSoft\Sql\Cache\PrimaryKeyColumnCache;
use AlphaSoft\Sql\DoctrineManager;
use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\Sql\Mapping\PrimaryKeyColumn;
use AlphaSoft\AsLinkOrm\Cache\ColumnCache;
use AlphaSoft\AsLinkOrm\Cache\PrimaryKeyColumnCache;
use AlphaSoft\AsLinkOrm\DoctrineManager;
use AlphaSoft\AsLinkOrm\Mapping\Column;
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn;
use LogicException;
use SplObjectStorage;

Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Column.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace AlphaSoft\Sql\Mapping;
namespace AlphaSoft\AsLinkOrm\Mapping;

class Column
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/PrimaryKeyColumn.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace AlphaSoft\Sql\Mapping;
namespace AlphaSoft\AsLinkOrm\Mapping;

final class PrimaryKeyColumn extends Column
{
Expand Down
12 changes: 6 additions & 6 deletions src/Repository/Repository.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace AlphaSoft\Sql\Repository;
namespace AlphaSoft\AsLinkOrm\Repository;

use AlphaSoft\DataModel\Model;
use AlphaSoft\DataModel\Factory\ModelFactory;
use AlphaSoft\Sql\DoctrineManager;
use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\Sql\Relation\HasEntity;
use AlphaSoft\AsLinkOrm\DoctrineManager;
use AlphaSoft\AsLinkOrm\Mapping\Column;
use AlphaSoft\AsLinkOrm\Entity\HasEntity;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Test\AlphaSoft\Sql\Model\Post;

abstract class Repository
{
Expand Down Expand Up @@ -148,7 +148,7 @@ protected static function generateWhereQuery(QueryBuilder $query, array $argumen
{
foreach ($arguments as $property => $value) {
if (is_array($value)) {
$query->andWhere($query->expr()->in($property, $query->createPositionalParameter($value, ArrayParameterType::STRING)));
$query->andWhere($query->expr()->in($property, $query->createPositionalParameter($value, Connection::PARAM_STR_ARRAY)));
continue;
}
$query->andWhere($property . ' = ' . $query->createPositionalParameter($value));
Expand Down
10 changes: 5 additions & 5 deletions tests/Model/Post.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Test\AlphaSoft\Sql\Model;
namespace Test\AlphaSoft\AsLinkOrm\Model;

use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\Sql\Mapping\PrimaryKeyColumn;
use AlphaSoft\Sql\Relation\HasEntity;
use Test\AlphaSoft\Sql\Repository\PostRepository;
use AlphaSoft\AsLinkOrm\Mapping\Column;
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn;
use AlphaSoft\AsLinkOrm\Entity\HasEntity;
use Test\AlphaSoft\AsLinkOrm\Repository\PostRepository;

final class Post extends HasEntity
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Model/User.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Test\AlphaSoft\Sql\Model;
namespace Test\AlphaSoft\AsLinkOrm\Model;

use AlphaSoft\Sql\Mapping\Column;
use AlphaSoft\Sql\Mapping\PrimaryKeyColumn;
use AlphaSoft\Sql\Relation\HasEntity;
use Test\AlphaSoft\Sql\Repository\UserRepository;
use AlphaSoft\AsLinkOrm\Mapping\Column;
use AlphaSoft\AsLinkOrm\Mapping\PrimaryKeyColumn;
use AlphaSoft\AsLinkOrm\Entity\HasEntity;
use Test\AlphaSoft\AsLinkOrm\Repository\UserRepository;

final class User extends HasEntity
{
Expand Down
7 changes: 3 additions & 4 deletions tests/Repository/PostRepository.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

namespace Test\AlphaSoft\Sql\Repository;
namespace Test\AlphaSoft\AsLinkOrm\Repository;

use AlphaSoft\Sql\Repository\Repository;
use Test\AlphaSoft\Sql\Model\Post;
use Test\AlphaSoft\Sql\Model\User;
use AlphaSoft\AsLinkOrm\Repository\Repository;
use Test\AlphaSoft\AsLinkOrm\Model\Post;

class PostRepository extends Repository
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Repository/UserRepository.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Test\AlphaSoft\Sql\Repository;
namespace Test\AlphaSoft\AsLinkOrm\Repository;

use AlphaSoft\Sql\Repository\Repository;
use Test\AlphaSoft\Sql\Model\User;
use AlphaSoft\AsLinkOrm\Repository\Repository;
use Test\AlphaSoft\AsLinkOrm\Model\User;

class UserRepository extends Repository
{
Expand Down
23 changes: 17 additions & 6 deletions tests/RepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Test\AlphaSoft\Sql;
namespace Test\AlphaSoft\AsLinkOrm;

use AlphaSoft\Sql\DoctrineManager;
use AlphaSoft\AsLinkOrm\DoctrineManager;
use PDO;
use PHPUnit\Framework\TestCase;
use Test\AlphaSoft\Sql\Model\Post;
use Test\AlphaSoft\Sql\Model\User;
use Test\AlphaSoft\Sql\Repository\PostRepository;
use Test\AlphaSoft\Sql\Repository\UserRepository;
use Test\AlphaSoft\AsLinkOrm\Model\Post;
use Test\AlphaSoft\AsLinkOrm\Model\User;
use Test\AlphaSoft\AsLinkOrm\Repository\PostRepository;
use Test\AlphaSoft\AsLinkOrm\Repository\UserRepository;

class RepositoryTest extends TestCase
{
Expand Down Expand Up @@ -126,6 +126,17 @@ public function testHasMany()
$this->assertEquals('First Post', $relatedPosts[0]->get('title'));
}

public function testMultipleFind()
{
$this->insertTestData();

/**
* @var User $user
*/
$users = $this->userRepository->findBy(['firstname' => ['John', 'Jane']]);
$this->assertCount(2, iterator_to_array($users, false));
}

public function testToDbWithDefaultColumnMapping()
{
$user = new User([
Expand Down

0 comments on commit 2705c00

Please sign in to comment.