public function testMe() { $utilities = \lillockey\Utilities\App\InstanceHolder::util(); $this->assertTrue($utilities instanceof \lillockey\Utilities\App\Utilities, "Utilities loaded"); $info = $utilities->get_file_information(__FILE__); $this->assertTrue($info instanceof \lillockey\Utilities\App\Containers\FileInformationResults, "Loading file type results"); $this->assertEquals('text/x-php', $info->type(), 'Checking the MIME-type'); $this->assertEquals(null, $info->recommended_extension(), 'Checking the recommended extension'); }
public function __construct($json) { $util = InstanceHolder::util(); if ($util->is_json($json)) { $j_array = json_decode($json, true); parent::__construct($j_array); $this->json_error = json_last_error(); $this->json_error_msg = json_last_error_msg(); } else { parent::__construct(new \stdClass()); } }
public function testValidation() { $u = \lillockey\Utilities\App\InstanceHolder::util(); $this->assertTrue($u instanceof \lillockey\Utilities\App\Utilities, "Utilities loaded"); //Email validation $valid_email_mx_okay = "*****@*****.**"; $valid_email_mx_nokay = "*****@*****.**"; $invalid_email = "bibbitybobbityboo"; $this->assertFalse($u->validate_email($valid_email_mx_nokay, true), "Email Validation w/ MX - Good Form - Bad MX"); $this->assertTrue($u->validate_email($valid_email_mx_nokay, false), "Email Validation w/o MX - Good Form - Bad MX"); $this->assertTrue($u->validate_email($valid_email_mx_okay, true), "Email Validation w/ MX - Good Form - Good MX"); $this->assertFalse($u->validate_email($invalid_email, false), "Email Validation w/o MX - Bad Form - Bad MX"); }
/** * Checks the image data provided to see if it's actually an image * @param $data * @return bool|string */ public function validate_image_data(&$data) { $util = InstanceHolder::util(); try { //This should only break if there's something hostile $util->get_data_information($data); } catch (\Exception $e) { return "There was a problem getting the information"; } //So ... it IS a real thing. try { //This will break if it isn't an image getimagesizefromstring($data); } catch (\Exception $e) { return "The image wasn't a valid type after all"; } //So ... it's an image ... seems legit return true; }
/** * Retrieve the value raw * @param $key * @return mixed */ public function raw($key) { $util = InstanceHolder::util(); if ($key === null) { $val = null; } else { $ar = (array) $this; $val = $util->getArrayValue($ar, $key); } return $val; }
/** * Inserts a new record into the given table with columns/values determined by associative array $fields * @param string $table * @param array $fields * @return boolean */ public function insert($table, array $fields) { $table = $this->config->table($table); if ($this->field_name_is_valid($table) === false) { return false; } //Build column/value lists $columns = ""; $values = ""; $i = 0; $submitted_values = array(); foreach ($fields as $column => $value) { if ($this->field_name_is_valid($column) === false) { continue; } if ($value === null) { continue; } if (InstanceHolder::util()->str_left_is($value, '#__')) { $function_to_use = substr($value, 3, strlen($value) - 3); if ($i == 0) { //If this is the first column/value pair $columns = $column; //Make the columns value = the column name $values = $function_to_use; //Set the value to the premade key } else { //If this is any subsequent column/value pair, precede both the value and the column with a ',' $columns .= ", {$column}"; //Add the column value to the columns list $values .= ", {$function_to_use}"; //Add the premade key to the values list } } else { $key = "v{$i}"; //Make a reusable key $submitted_values[$key] = $value; //Add the validated column's value into the array to be submitted to the query if ($i == 0) { //If this is the first column/value pair $columns = $column; //Make the columns value = the column name $values = ":{$key}"; //Set the value to the premade key } else { //If this is any subsequent column/value pair, precede both the value and the column with a ',' $columns .= ", {$column}"; //Add the column value to the columns list $values .= ", :{$key}"; //Add the premade key to the values list } } $i++; //Next } //Quick accepted column check. if (sizeof($submitted_values) < 1) { return false; } //Create the query $query = "INSERT INTO `{$table}` ({$columns}) VALUES ({$values});"; //Run the query $r = $this->execute_query($query, $submitted_values); return $r->exec() ? $r->id() : false; }