proceed further with beans
This commit is contained in:
		
							
								
								
									
										9
									
								
								beans/OrderBy.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								beans/OrderBy.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace DatabaseHelper\beans;
 | 
			
		||||
 | 
			
		||||
use DatabaseHelper\enums\Order;
 | 
			
		||||
 | 
			
		||||
class OrderBy {
 | 
			
		||||
    public string $col;
 | 
			
		||||
    public Order $order;
 | 
			
		||||
}
 | 
			
		||||
@@ -10,19 +10,43 @@ use http\Exception\InvalidArgumentException;
 | 
			
		||||
class Schema
 | 
			
		||||
{
 | 
			
		||||
    public string $name = '';
 | 
			
		||||
    public Primary $primary;
 | 
			
		||||
    public Primary $id;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<string, Column>
 | 
			
		||||
     */
 | 
			
		||||
    public array $columns = [];
 | 
			
		||||
    public array $cols = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<string, Reference>
 | 
			
		||||
     */
 | 
			
		||||
    public array $references = [];
 | 
			
		||||
    public array $refs = [];
 | 
			
		||||
 | 
			
		||||
    public Engine $engine = Engine::INNODB;
 | 
			
		||||
    public Charset $charset = Charset::UTF8;
 | 
			
		||||
    public Collation $collation = Collation::UTF8_GENERAL_CI;
 | 
			
		||||
 | 
			
		||||
    public function existsCol(string $name): bool {
 | 
			
		||||
        return isset($this->cols[$name]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function reqCol(string $name): void {
 | 
			
		||||
        if (!$this->existsCol($name))
 | 
			
		||||
            throw new InvalidArgumentException("Column $name does not exist in schema $this->name.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCol(string $name): Column {
 | 
			
		||||
        return $this->cols[$name];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function existsRef(Schema $other): bool {
 | 
			
		||||
        $otherId = $other->id;
 | 
			
		||||
        // TODO
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function reqRef(Schema $other): void {
 | 
			
		||||
        if (!$this->existsRef($other))
 | 
			
		||||
            throw new InvalidArgumentException("A reference to $other->name is not defined in  $this->name.");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user