Skip to content

Commit b180c60

Browse files
committed
Started normal function development
1 parent c4787d9 commit b180c60

File tree

11 files changed

+365
-109
lines changed

11 files changed

+365
-109
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
errors.txt
3-
test
3+
test
4+
/.vscode

src/AB/DataSet.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
namespace WhizSid\ArrayBase\AB;
33

4-
use WhizSid\ArrayBase\AB\Traits\Aliasable;
54
use WhizSid\ArrayBase\AB\DataSet\Row;
65
use WhizSid\ArrayBase\KeepAB;
76
use WhizSid\ArrayBase\ABException;
87
use WhizSid\ArrayBase\AB\DataSet\Row\Cell;
98
use WhizSid\ArrayBase\AB\Table\Column;
9+
use WhizSid\ArrayBase\Helper;
1010

1111
class DataSet extends KeepAB{
1212
/**
@@ -224,17 +224,21 @@ public function fetchAssoc(){
224224
/**
225225
* Returning the cell by row index and cell name or index
226226
*
227-
* @param int|string $aliasOrIndex
227+
* @param int|string|Column $column
228228
* @param int $rowIndex
229229
* @return Cell
230230
*/
231-
public function getCell($aliasOrIndex,$rowIndex){
231+
public function getCell($column,$rowIndex){
232232
$row = $this->getByIndex($rowIndex);
233233

234-
if(is_numeric($aliasOrIndex))
235-
$index = $aliasOrIndex;
234+
if(Helper::isColumn($column)){
235+
$column = $column->getTable()->getName().'.'.$column->getName();
236+
}
237+
238+
if(is_numeric($column))
239+
$index = $column;
236240
else
237-
$index = $this->searchAlias($aliasOrIndex);
241+
$index = $this->searchAlias($column);
238242

239243
return $row->getCell($index);
240244
}

src/Helper.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ public static function parseTable($ab,$name,$arr){
124124
/**
125125
* Checking the given value is in the correct type
126126
*/
127-
public function __callStatic($name, $arguments)
128-
{
129-
if(strtolower(substr($name,0,2))=='is'&&count($arguments)==1){
130-
if(isset(self::$types[strtolower(substr($name,2))]))
131-
return self::$types[strtolower(substr($name,2))]==get_class($arguments[0]);
132-
else
133-
// <ABE28> \\
134-
throw new ABException("Invalid type supplied. Can not find the type $name.",28);
135-
}
136-
else
137-
throw new BadMethodCallException("Invalid function called.");
138-
}
127+
public function __callStatic($name, $arguments)
128+
{
129+
if(strtolower(substr($name,0,2))=='is'&&count($arguments)==1){
130+
if(isset(self::$types[strtolower(substr($name,2))]))
131+
return self::$types[strtolower(substr($name,2))]==get_class($arguments[0]);
132+
else
133+
// <ABE28> \\
134+
throw new ABException("Invalid type supplied. Can not find the type $name.",28);
135+
}
136+
else
137+
throw new BadMethodCallException("Invalid function called.");
138+
}
139139
}

src/Query/Clauses/Where.php

+2-88
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,8 @@
22
namespace WhizSid\ArrayBase\Query\Clauses;
33

44
use WhizSid\ArrayBase\KeepQuery;
5-
use WhizSid\ArrayBase\Query\Objects\Comparison;
6-
use WhizSid\ArrayBase\AB\Traits\KeepDataSet;
5+
use WhizSid\ArrayBase\Query\Traits\ConditionBehaviour;
76

87
class Where extends KeepQuery {
9-
use KeepDataSet;
10-
/**
11-
* Comparisons in the given order
12-
*
13-
* @var Comparison[]
14-
*/
15-
protected $comparisons = [];
16-
/**
17-
* Operators that combine comparisons
18-
*
19-
* 1 for or and 0 for and
20-
*
21-
* @var int[]
22-
*/
23-
protected $operators = [];
24-
25-
public function __construct($leftSide,$operator,$rightSide=null)
26-
{
27-
$this->addComparison($leftSide,$operator,$rightSide);
28-
}
29-
/**
30-
* Adding a comparison to where clause
31-
*
32-
* @param mixed $leftSide
33-
* @param mixed $operator
34-
* @param mixed $rightSide
35-
* @return void
36-
*/
37-
protected function addComparison($leftSide,$operator,$rightSide=null){
38-
$comparison = new Comparison($leftSide,$operator,$rightSide);
39-
$this->comparisons[] = $comparison;
40-
}
41-
/**
42-
* Add a comparison with and operator
43-
*
44-
* @param mixed $leftSide
45-
* @param mixed $operator
46-
* @param mixed $rightSide
47-
* @return self
48-
*/
49-
public function and($leftSide,$operator,$rightSide=null){
50-
$this->operators[]=0;
51-
$this->addComparison($leftSide,$operator,$rightSide);
52-
return $this;
53-
}
54-
/**
55-
* Add a comparison with or operator
56-
*
57-
* @param mixed $leftSide
58-
* @param mixed $operator
59-
* @param mixed $rightSide
60-
* @return self
61-
*/
62-
public function or($leftSide,$operator,$rightSide=null){
63-
$this->operators[]=1;
64-
$this->addComparison($leftSide,$operator,$rightSide);
65-
return $this;
66-
}
67-
/**
68-
* Executing the where clause and returning the value
69-
*
70-
* @param int $rowIndex
71-
* @return bool
72-
*/
73-
public function execute($rowIndex){
74-
75-
$value = TRUE;
76-
77-
foreach ($this->comparisons as $key => $comparison) {
78-
$currentStatus = $comparison->setDataSet($this->dataSet)->execute($rowIndex);
79-
80-
if($key==0){
81-
$value = $currentStatus;
82-
} else {
83-
$operator = $this->operators[$key-1];
84-
85-
if($operator)
86-
$value = $value||$currentStatus;
87-
else
88-
$value = $value&&$currentStatus;
89-
}
90-
91-
}
92-
93-
return $value;
94-
}
8+
use ConditionBehaviour;
959
}

src/Query/Objects/Condition.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace WhizSid\ArrayBase\Query\Objects;
3+
4+
use WhizSid\ArrayBase\Query\Traits\ConditionBehaviour;
5+
6+
class Condition {
7+
use ConditionBehaviour;
8+
}
+54-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
11
<?php
22
namespace WhizSid\ArrayBase\Query\Objects\Functions;
33

4-
interface ABFunction {
4+
use WhizSid\ArrayBase\ABException;
5+
use WhizSid\ArrayBase\Query\Objects\Parser;
6+
7+
class ABFunction {
8+
protected $name="";
59
/**
610
* Executing the function
711
*
812
* @return void
913
*/
10-
public function execute();
14+
public function execute(){
15+
16+
}
17+
/**
18+
* Validating the arguments
19+
*
20+
* @param int $rowId
21+
* @throws ABException
22+
*/
23+
public function validate($rowId){
24+
25+
}
26+
/**
27+
* throwing an argument error exception
28+
*
29+
* @throws ABException
30+
*/
31+
protected function argumentError(){
32+
// <ABE33> \\
33+
throw new ABException("Invalid argument given to function ".$this->name.".",33);
34+
}
35+
/**
36+
* Validating an basic argument
37+
*
38+
* @param mixed $arg
39+
*/
40+
public function validateBasicArgument($arg){
41+
if(!Helper::isColumn($arg)&&!is_string($arg)&&!is_numeric($arg)&&!is_null($arg))
42+
$this->argumentError();
43+
}
44+
/**
45+
* Parsing and argument
46+
*
47+
* @param mixed $arg
48+
* @param int $rowIndex
49+
* @return mixed
50+
*/
51+
protected function parseArgument($arg,$rowIndex){
52+
if(Helper::isColumn($arg)){
53+
/** @var Column $arg */
54+
$value = $this->dataSet->getCell($arg,$rowIndex);
55+
} else {
56+
$value = $arg;
57+
}
58+
59+
$parsedValue = Parser::parseValue($value);
60+
61+
return $parsedValue;
62+
}
1163
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace WhizSid\ArrayBase\Query\Objects;
3+
4+
use WhizSid\ArrayBase\Query\Objects\Functions\ABFunction;
5+
6+
class Concat extends ABFunction {
7+
/**
8+
* Column names or strings to concat
9+
*
10+
* @var mixed[]
11+
*/
12+
protected $concats=[];
13+
/**
14+
* Function name
15+
*
16+
* @var string
17+
*/
18+
protected $name = "concat";
19+
/**
20+
* Parsing variables to concat
21+
*
22+
* @param mixed ...$args
23+
*/
24+
public function __construct(...$args)
25+
{
26+
$this->concats = $args;
27+
}
28+
/**
29+
* Validating arguments
30+
*
31+
* @return void
32+
*/
33+
public function validate(){
34+
foreach ($this->concats as $key => $concat) {
35+
$this->validateBasicArgument($concat);
36+
}
37+
}
38+
/**
39+
* @inheritDoc
40+
*
41+
*/
42+
public function execute(int $rowId){
43+
$concated = "";
44+
45+
foreach ($this->concats as $key => $concat) {
46+
47+
$parsedValue = $this->parseArgument($concat,$rowId);
48+
49+
if(!$parsedValue)
50+
$parsedValue = "";
51+
52+
$concated .= $parsedValue;
53+
}
54+
55+
return $concated;
56+
}
57+
}

0 commit comments

Comments
 (0)