From 2efc085d3f60115721d9ff3ae565a46b27bc489b Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <> Date: Tue, 31 Jan 2023 00:31:42 +0100 Subject: [PATCH] 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 --- phpxpress/Breadcrumb.php | 7 +++--- phpxpress/Card.php | 5 ++--- phpxpress/Code.php | 47 +++++++++++++++++++--------------------- phpxpress/Dropdown.php | 5 ++--- phpxpress/Table.php | 35 +++++++++++++++--------------- 5 files changed, 46 insertions(+), 53 deletions(-) diff --git a/phpxpress/Breadcrumb.php b/phpxpress/Breadcrumb.php index 2c88985..6c19e1b 100644 --- a/phpxpress/Breadcrumb.php +++ b/phpxpress/Breadcrumb.php @@ -1,7 +1,6 @@ $link){ $this->addElement($caption, $link); @@ -60,7 +59,7 @@ function setActiveLocation($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; } diff --git a/phpxpress/Card.php b/phpxpress/Card.php index b82d025..7adf5d0 100644 --- a/phpxpress/Card.php +++ b/phpxpress/Card.php @@ -1,7 +1,6 @@ imageSource = $imageSource; } @@ -211,7 +210,7 @@ */ function onFieldDisplaying($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; } diff --git a/phpxpress/Code.php b/phpxpress/Code.php index fdd5f69..48c5b73 100644 --- a/phpxpress/Code.php +++ b/phpxpress/Code.php @@ -1,37 +1,34 @@ "primary", + "gray" => "secondary", + "green" => "success", + "red" => "danger", + "yellow" => "warning", + "cyan" => "info", + "white" => "light", + "black" => "dark"); public static function bootstrapColors($color){ - if($color == 'blue') - return 'primary'; - if($color == 'gray') - return 'secondary'; + if(array_key_exists($color, self::$colors_array)){ + return self::$colors_array[$color]; + } - if($color == 'green') - return 'success'; + if(in_array($color, self::$colors_array)){ + return $color; + } - if($color == 'red') - 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'); + throw new \InvalidArgumentException("Color $color is not valid. Available colors: blue, gray, green, red, yellow, cyan, white, black"); } + + public static function phpxpress_version(){ + return "1.0.4"; + } + } ?> \ No newline at end of file diff --git a/phpxpress/Dropdown.php b/phpxpress/Dropdown.php index 35babc0..bbf1b0d 100644 --- a/phpxpress/Dropdown.php +++ b/phpxpress/Dropdown.php @@ -1,7 +1,6 @@ size = "btn-sm"; 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){ if(!is_bool($bool)) - throw new InvalidArgumentException('Parameter must be a bool.'); + throw new \InvalidArgumentException('Parameter must be a bool.'); $this->darkTheme = $bool; diff --git a/phpxpress/Table.php b/phpxpress/Table.php index aa2d2e7..b99befa 100644 --- a/phpxpress/Table.php +++ b/phpxpress/Table.php @@ -1,7 +1,6 @@ dataSource)){ - throw new BadFunctionCallException('Error: datasource not set.'); + throw new \BadFunctionCallException('Error: datasource not set.'); } $tableClass = "table"; @@ -151,7 +150,7 @@ */ function setDataSource(Array $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)){ $this->dataSource = []; @@ -166,7 +165,7 @@ $is_array_of_arrays = true; } 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)'); } @@ -179,10 +178,10 @@ return $is_array_of_arrays; } 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)'); })) > 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)'); } } @@ -227,7 +226,7 @@ function setCustomCaptions(Array $captions){ 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); $expected = count($this->columnCaptions); @@ -235,7 +234,7 @@ if($provided == $expected) $this -> columnCaptions = $captions; 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); } @@ -276,7 +275,7 @@ function invisible_column($column_name){ 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])){ $array_keys = array_keys($this -> dataSource[0]); @@ -286,12 +285,12 @@ } 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(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); } @@ -315,42 +314,42 @@ */ function onValueDisplaying($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; } function setDarkTheme($bool){ if(!is_bool($bool)){ - throw new InvalidArgumentException('Parameter must be a boolean.'); + throw new \InvalidArgumentException('Parameter must be a boolean.'); } $this->darkTheme = $bool; } function setStripedRows($bool){ if(!is_bool($bool)){ - throw new InvalidArgumentException('Parameter must be a boolean.'); + throw new \InvalidArgumentException('Parameter must be a boolean.'); } $this->stripedRows = $bool; } function setBordered($bool){ if(!is_bool($bool)){ - throw new InvalidArgumentException('Parameter must be a boolean.'); + throw new \InvalidArgumentException('Parameter must be a boolean.'); } $this->bordered = $bool; } function setHoverAnimation($bool){ if(!is_bool($bool)){ - throw new InvalidArgumentException('Parameter must be a boolean.'); + throw new \InvalidArgumentException('Parameter must be a boolean.'); } $this->hoverAnimation = $bool; } function setSmall($bool){ if(!is_bool($bool)){ - throw new InvalidArgumentException('Parameter must be a boolean.'); + throw new \InvalidArgumentException('Parameter must be a boolean.'); } $this->small = $bool; } @@ -358,7 +357,7 @@ // to be used before setting the datasource function setPedanticTypeCheck($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)){ echo "WarningUse of pedantic type check after datasource is set. Instruction ignored.";