Update to 1.0.4

* It is now possible to use both Custom and Bootstrap colors;
* Fixed some reference errors
* Version is now a function rather than a comment in the source code
This commit is contained in:
Alessandro Ferro 2023-01-31 00:31:42 +01:00
parent adc6089ba1
commit 2efc085d3f
5 changed files with 46 additions and 53 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
/** /*
* PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -32,7 +31,7 @@
*/ */
function setDataSource($dataSource){ function setDataSource($dataSource){
if(!is_array($dataSource)) if(!is_array($dataSource))
throw new InvalidArgumentException('Parameter dataSource must be an array.'); throw new \InvalidArgumentException('Parameter dataSource must be an array.');
foreach($dataSource as $caption => $link){ foreach($dataSource as $caption => $link){
$this->addElement($caption, $link); $this->addElement($caption, $link);
@ -60,7 +59,7 @@
function setActiveLocation($activeLocation){ function setActiveLocation($activeLocation){
if(!is_scalar($activeLocation) && !is_string($activeLocation)) if(!is_scalar($activeLocation) && !is_string($activeLocation))
throw new InvalidArgumentException('Parameter activeLocation can be either an int or a string. None of these provided.'); throw new \InvalidArgumentException('Parameter activeLocation can be either an int or a string. None of these provided.');
$this->activeLocation = $activeLocation; $this->activeLocation = $activeLocation;
} }

View File

@ -1,7 +1,6 @@
<?php <?php
/** /**
* PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -57,7 +56,7 @@
function setImageSource($imageSource){ function setImageSource($imageSource){
if(!is_string($imageSource)) if(!is_string($imageSource))
throw new InvalidArgumentException('Parameter imageSource must be a string.'); throw new \InvalidArgumentException('Parameter imageSource must be a string.');
$this->imageSource = $imageSource; $this->imageSource = $imageSource;
} }
@ -211,7 +210,7 @@
*/ */
function onFieldDisplaying($functionName){ function onFieldDisplaying($functionName){
if(!is_callable($functionName)) if(!is_callable($functionName))
throw new InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function."); throw new \InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function.");
$this -> onFieldDisplayingFunctionName = $functionName; $this -> onFieldDisplayingFunctionName = $functionName;
} }

View File

@ -1,37 +1,34 @@
<?php <?php
namespace PhpXpress;
class Code{ class Code{
public static function doublequote($string){ private static $colors_array = array( "blue" => "primary",
return '"' . $string . '"'; "gray" => "secondary",
} "green" => "success",
"red" => "danger",
"yellow" => "warning",
"cyan" => "info",
"white" => "light",
"black" => "dark");
public static function bootstrapColors($color){ public static function bootstrapColors($color){
if($color == 'blue')
return 'primary';
if($color == 'gray') if(array_key_exists($color, self::$colors_array)){
return 'secondary'; return self::$colors_array[$color];
}
if($color == 'green') if(in_array($color, self::$colors_array)){
return 'success'; return $color;
}
if($color == 'red') throw new \InvalidArgumentException("Color $color is not valid. Available colors: blue, gray, green, red, yellow, cyan, white, black");
return 'danger';
if($color == 'yellow')
return 'warning';
if($color == 'cyan')
return 'info';
if($color == 'white')
return 'light';
if($color == 'black')
return 'dark';
throw new InvalidArgumentException('Color not valid. Available colors: blue, gray, green, red, yellow, cyan, white, black');
} }
public static function phpxpress_version(){
return "1.0.4";
}
} }
?> ?>

View File

@ -1,7 +1,6 @@
<?php <?php
/** /**
* PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -47,12 +46,12 @@
$this->size = "btn-sm"; $this->size = "btn-sm";
else else
throw new InvalidArgumentException('Parameter size must be either default, large or small.'); throw new \InvalidArgumentException('Parameter size must be either default, large or small.');
} }
public function setDarkTheme($bool){ public function setDarkTheme($bool){
if(!is_bool($bool)) if(!is_bool($bool))
throw new InvalidArgumentException('Parameter must be a bool.'); throw new \InvalidArgumentException('Parameter must be a bool.');
$this->darkTheme = $bool; $this->darkTheme = $bool;

View File

@ -1,7 +1,6 @@
<?php <?php
/** /**
* PhpXpress v1.0.3
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -69,7 +68,7 @@
function draw(){ function draw(){
if(!isset($this->dataSource)){ if(!isset($this->dataSource)){
throw new BadFunctionCallException('Error: datasource not set.'); throw new \BadFunctionCallException('Error: datasource not set.');
} }
$tableClass = "table"; $tableClass = "table";
@ -151,7 +150,7 @@
*/ */
function setDataSource(Array $dataSource){ function setDataSource(Array $dataSource){
if(isset($this-> dataSource)) if(isset($this-> dataSource))
throw new BadFunctionCallException("Cannot add datasource to a Table already having a datasource"); throw new \BadFunctionCallException("Cannot add datasource to a Table already having a datasource");
if(empty($dataSource)){ if(empty($dataSource)){
$this->dataSource = []; $this->dataSource = [];
@ -166,7 +165,7 @@
$is_array_of_arrays = true; $is_array_of_arrays = true;
} }
else{ else{
throw new InvalidArgumentException('Parameter "datasource" must be an' . throw new \InvalidArgumentException('Parameter "datasource" must be an' .
'array of array(s) or array of object(s)'); 'array of array(s) or array of object(s)');
} }
@ -179,10 +178,10 @@
return $is_array_of_arrays; return $is_array_of_arrays;
} }
else else
throw new InvalidArgumentException('Parameter "datasource" must be an' . throw new \InvalidArgumentException('Parameter "datasource" must be an' .
'array of array(s) or array of object(s)'); 'array of array(s) or array of object(s)');
})) > 0){ })) > 0){
throw new InvalidArgumentException('Parameter "datasource" must be an' . throw new \InvalidArgumentException('Parameter "datasource" must be an' .
'array of array(s) or array of object(s)'); 'array of array(s) or array of object(s)');
} }
} }
@ -227,7 +226,7 @@
function setCustomCaptions(Array $captions){ function setCustomCaptions(Array $captions){
if(empty($this->dataSource)) if(empty($this->dataSource))
throw new BadFunctionCallException('Before setting Custom captions, a non empty datasource must be provided first.'); throw new \BadFunctionCallException('Before setting Custom captions, a non empty datasource must be provided first.');
$provided = count($captions); $provided = count($captions);
$expected = count($this->columnCaptions); $expected = count($this->columnCaptions);
@ -235,7 +234,7 @@
if($provided == $expected) if($provided == $expected)
$this -> columnCaptions = $captions; $this -> columnCaptions = $captions;
else else
throw new LengthException('Number of provided captions not matching the datasource ones. throw new \LengthException('Number of provided captions not matching the datasource ones.
Provided: ' . $provided . "; Expected: " . $expected); Provided: ' . $provided . "; Expected: " . $expected);
} }
@ -276,7 +275,7 @@
function invisible_column($column_name){ function invisible_column($column_name){
if(!isset($this->dataSource) || empty($this->dataSource)) if(!isset($this->dataSource) || empty($this->dataSource))
throw new BadFunctionCallException('Unable to call invisible_column() if the datasource is not set or empty.'); throw new \BadFunctionCallException('Unable to call invisible_column() if the datasource is not set or empty.');
if(is_array($this->dataSource[0])){ if(is_array($this->dataSource[0])){
$array_keys = array_keys($this -> dataSource[0]); $array_keys = array_keys($this -> dataSource[0]);
@ -286,12 +285,12 @@
} }
if(!in_array($column_name, $array_keys)){ if(!in_array($column_name, $array_keys)){
throw new InvalidArgumentException("The provided column $column_name is not present in the datasource's column keys"); throw new \InvalidArgumentException("The provided column $column_name is not present in the datasource's column keys");
} }
if(isset($this->invisible_columns)){ if(isset($this->invisible_columns)){
if(in_array($column_name, $this->invisible_columns)) if(in_array($column_name, $this->invisible_columns))
throw new InvalidArgumentException("The provided column $column_name is already invisible"); throw new \InvalidArgumentException("The provided column $column_name is already invisible");
array_push($this->invisible_columns, $column_name); array_push($this->invisible_columns, $column_name);
} }
@ -315,42 +314,42 @@
*/ */
function onValueDisplaying($functionName){ function onValueDisplaying($functionName){
if(!is_callable($functionName)) if(!is_callable($functionName))
throw new InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function."); throw new \InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function.");
$this -> onValueDisplayingFunctionName = $functionName; $this -> onValueDisplayingFunctionName = $functionName;
} }
function setDarkTheme($bool){ function setDarkTheme($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
$this->darkTheme = $bool; $this->darkTheme = $bool;
} }
function setStripedRows($bool){ function setStripedRows($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
$this->stripedRows = $bool; $this->stripedRows = $bool;
} }
function setBordered($bool){ function setBordered($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
$this->bordered = $bool; $this->bordered = $bool;
} }
function setHoverAnimation($bool){ function setHoverAnimation($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
$this->hoverAnimation = $bool; $this->hoverAnimation = $bool;
} }
function setSmall($bool){ function setSmall($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
$this->small = $bool; $this->small = $bool;
} }
@ -358,7 +357,7 @@
// to be used before setting the datasource // to be used before setting the datasource
function setPedanticTypeCheck($bool){ function setPedanticTypeCheck($bool){
if(!is_bool($bool)){ if(!is_bool($bool)){
throw new InvalidArgumentException('Parameter must be a boolean.'); throw new \InvalidArgumentException('Parameter must be a boolean.');
} }
if(isset($this->datasource)){ if(isset($this->datasource)){
echo "<b>Warning</b>Use of pedantic type check after datasource is set. Instruction ignored."; echo "<b>Warning</b>Use of pedantic type check after datasource is set. Instruction ignored.";