Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - Removed fCore::stringlike()
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Apr 12, 2012
1 parent 843e4a0 commit ec66b71
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 60 deletions.
2 changes: 1 addition & 1 deletion classes/fActiveRecord.php
Expand Up @@ -885,7 +885,7 @@ protected function hash($data)
$pk_column,
is_array($data) ? $data[$pk_column] : $data
);
if (fCore::stringlike($pk_data[$pk_column])) {
if (is_numeric($pk_data[$pk_column]) || is_object($pk_data[$pk_column])) {
$pk_data[$pk_column] = (string) $pk_data[$pk_column];
}
}
Expand Down
26 changes: 0 additions & 26 deletions classes/fCore.php
Expand Up @@ -29,7 +29,6 @@ class fCore
const handleException = 'fCore::handleException';
const reset = 'fCore::reset';
const sendMessagesOnShutdown = 'fCore::sendMessagesOnShutdown';
const stringlike = 'fCore::stringlike';


/**
Expand Down Expand Up @@ -683,7 +682,6 @@ static public function reset()
self::$exception_handler_parameters = array();
self::$exception_message = NULL;
self::$handles_errors = FALSE;
self::$toss_callbacks = array();
}


Expand Down Expand Up @@ -775,30 +773,6 @@ static private function sendMessageToDestination($type, $message)
}


/**
* Returns `TRUE` for non-empty strings, numbers, objects, empty numbers and string-like numbers (such as `0`, `0.0`, `'0'`)
*
* @param mixed $value The value to check
* @return boolean If the value is string-like
*/
static public function stringlike($value)
{
if (!$value && !is_numeric($value)) {
return FALSE;
}

if (is_resource($value) || is_array($value) || $value === TRUE) {
return FALSE;
}

if (is_string($value) && !trim($value)) {
return FALSE;
}

return TRUE;
}


/**
* Forces use as a static class
*
Expand Down
2 changes: 1 addition & 1 deletion classes/fDate.php
Expand Up @@ -62,7 +62,7 @@ public function __construct($date=NULL)
} else {
if (is_object($date) && is_callable(array($date, '__toString'))) {
$date = $date->__toString();
} elseif (fCore::stringlike($date)) {
} elseif (is_numeric($date) || is_object($date)) {
$date = (string) $date;
}
$timestamp = strtotime(fTimestamp::fixISOWeek($date));
Expand Down
32 changes: 24 additions & 8 deletions classes/fEmail.php
Expand Up @@ -200,6 +200,22 @@ static public function reset()
}


/**
* Returns `TRUE` for non-empty strings, numbers, objects, empty numbers and string-like numbers (such as `0`, `0.0`, `'0'`)
*
* @param mixed $value The value to check
* @return boolean If the value is string-like
*/
static protected function stringlike($value)
{
if ((!is_string($value) && !is_object($value) && !is_numeric($value)) || !strlen(trim($value))) {
return FALSE;
}

return TRUE;
}


/**
* The file contents to attach
*
Expand Down Expand Up @@ -344,7 +360,7 @@ public function __get($method)
*/
public function addAttachment($filename, $mime_type, $contents)
{
if (!fCore::stringlike($filename)) {
if (!self::stringlike($filename)) {
throw new fProgrammerException(
'The filename specified, %s, does not appear to be a valid filename',
$filename
Expand Down Expand Up @@ -718,7 +734,7 @@ private function createSMIMEBody($to, $subject, $headers, $body)
*/
public function encrypt($recipients_smime_cert_file)
{
if (!fCore::stringlike($recipients_smime_cert_file)) {
if (!self::stringlike($recipients_smime_cert_file)) {
throw new fProgrammerException(
"The recipient's S/MIME certificate filename specified, %s, does not appear to be a valid filename",
$recipients_smime_cert_file
Expand Down Expand Up @@ -1118,7 +1134,7 @@ public function setSubject($subject)
*/
public function sign($senders_smime_cert_file, $senders_smime_pk_file, $senders_smime_pk_password)
{
if (!fCore::stringlike($senders_smime_cert_file)) {
if (!self::stringlike($senders_smime_cert_file)) {
throw new fProgrammerException(
"The sender's S/MIME certificate file specified, %s, does not appear to be a valid filename",
$senders_smime_cert_file
Expand All @@ -1131,7 +1147,7 @@ public function sign($senders_smime_cert_file, $senders_smime_pk_file, $senders_
);
}

if (!fCore::stringlike($senders_smime_pk_file)) {
if (!self::stringlike($senders_smime_pk_file)) {
throw new fProgrammerException(
"The sender's S/MIME primary key file specified, %s, does not appear to be a valid filename",
$senders_smime_pk_file
Expand Down Expand Up @@ -1212,7 +1228,7 @@ private function validate()
);
}

if (!fCore::stringlike($this->subject)) {
if (!self::stringlike($this->subject)) {
$validation_messages[] = self::compose(
"Please provide an email subject"
);
Expand All @@ -1224,21 +1240,21 @@ private function validate()
);
}

if (!fCore::stringlike($this->plaintext_body)) {
if (!self::stringlike($this->plaintext_body)) {
$validation_messages[] = self::compose(
"Please provide a plaintext email body"
);
}

// Make sure the attachments look good
foreach ($this->attachments as $filename => $file_info) {
if (!fCore::stringlike($file_info['mime-type'])) {
if (!self::stringlike($file_info['mime-type'])) {
$validation_messages[] = self::compose(
"No mime-type was specified for the attachment %s",
$filename
);
}
if (!fCore::stringlike($file_info['contents'])) {
if (!self::stringlike($file_info['contents'])) {
$validation_messages[] = self::compose(
"The attachment %s appears to be a blank file",
$filename
Expand Down
2 changes: 1 addition & 1 deletion classes/fHTML.php
Expand Up @@ -192,7 +192,7 @@ static public function sendHeader()
*/
static public function show($content, $css_class='')
{
if (!fCore::stringlike($content)) {
if ((!is_string($content) && !is_object($content) && !is_numeric($content)) || !strlen(trim($content))) {
return FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/fMoney.php
Expand Up @@ -563,7 +563,7 @@ private function makeMoney($money)

if (is_object($money) && is_callable(array($money, '__toString'))) {
$money = $money->__toString();
} elseif (fCore::stringlike($money)) {
} elseif (is_numeric($money) || is_object($money)) {
$money = (string) $money;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/fNumber.php
Expand Up @@ -240,7 +240,7 @@ static private function parse($number, $element)
{
if (is_object($number) && is_callable(array($number, '__toString'))) {
$number = $number->__toString();
} elseif (fCore::stringlike($number)) {
} else {
$number = (string) $number;
}
$number = trim($number);
Expand Down
6 changes: 3 additions & 3 deletions classes/fORMColumn.php
Expand Up @@ -470,7 +470,7 @@ static public function inspect($object, &$values, &$old_values, &$related_record
*/
static public function objectifyNumber($class, $column, $value)
{
if (!fCore::stringlike($value)) {
if (!is_string($value) && !is_numeric($value)) {
return $value;
}

Expand Down Expand Up @@ -761,7 +761,7 @@ static public function validateEmailColumns($object, &$values, &$old_values, &$r
}

foreach (self::$email_columns[$class] as $column => $enabled) {
if (!fCore::stringlike($values[$column])) {
if (!strlen($values[$column])) {
continue;
}
if (!preg_match('#^[a-z0-9\\.\'_\\-\\+]+@(?:[a-z0-9\\-]+\.)+[a-z]{2,}$#iD', $values[$column])) {
Expand Down Expand Up @@ -796,7 +796,7 @@ static public function validateLinkColumns($object, &$values, &$old_values, &$re
}

foreach (self::$link_columns[$class] as $column => $enabled) {
if (!fCore::stringlike($values[$column])) {
if (!strlen($values[$column])) {
continue;
}
if (!preg_match('#^(http(s)?://|/|([a-z0-9\\-]+\.)+[a-z]{2,})#i', $values[$column])) {
Expand Down
2 changes: 1 addition & 1 deletion classes/fORMDatabase.php
Expand Up @@ -335,7 +335,7 @@ static public function createOrderByClause($table, $order_bys)
$sql = array();

foreach ($order_bys as $column => $direction) {
if (!fCore::stringlike($column)) {
if ((!is_string($column) && !is_object($column) && !is_numeric($column)) || !strlen(trim($column))) {
throw new fProgrammerException(
'An invalid sort column, %s, was specified',
$column
Expand Down
5 changes: 4 additions & 1 deletion classes/fORMDate.php
Expand Up @@ -362,7 +362,10 @@ static public function makeTimestampObjects($object, &$values, &$old_values, &$r
*/
static public function objectifyTimestampWithTimezone(&$values, &$old_values, $timestamp_column, $timezone_column)
{
if (!fCore::stringlike($values[$timestamp_column])) {
if ((!is_string($values[$timestamp_column]) &&
!is_object($values[$timestamp_column]) &&
!is_numeric($values[$timestamp_column])) ||
!strlen(trim($values[$timestamp_column]))) {
return;
}

Expand Down
5 changes: 2 additions & 3 deletions classes/fORMFile.php
Expand Up @@ -600,7 +600,7 @@ static public function moveFromTemp($object, &$values, &$old_values, &$related_r
*/
static public function objectify($class, $column, $value)
{
if (!fCore::stringlike($value)) {
if (!is_string($value) && !is_numeric($value) && !is_object($value)) {
return $value;
}

Expand Down Expand Up @@ -943,8 +943,7 @@ static public function set($object, &$values, &$old_values, &$related_records, &
);
}

$file_path = $parameters[0];
$invalid_file = !fCore::stringlike($file_path);
$file_path = $parameters[0];

if (!$file_path || (!file_exists($file_path) && !file_exists($doc_root . $file_path))) {
throw new fEnvironmentException(
Expand Down
4 changes: 2 additions & 2 deletions classes/fORMMoney.php
Expand Up @@ -288,7 +288,7 @@ static public function makeMoneyObjects($object, &$values, &$old_values, &$relat
*/
static public function objectifyMoney($class, $column, $value)
{
if (!fCore::stringlike($value)) {
if (!is_string($value) && !is_numeric($value) && !is_object($value)) {
return $value;
}

Expand All @@ -315,7 +315,7 @@ static public function objectifyMoney($class, $column, $value)
*/
static public function objectifyMoneyWithCurrency(&$values, &$old_values, $value_column, $currency_column)
{
if (!fCore::stringlike($values[$value_column])) {
if (!is_string($values[$value_column]) && !is_numeric($values[$value_column]) && !is_object($values[$value_column])) {
return;
}

Expand Down
20 changes: 18 additions & 2 deletions classes/fORMValidation.php
Expand Up @@ -507,7 +507,7 @@ static private function checkPrimaryKeys($object, &$values, &$old_values)
}
$old_value = fActiveRecord::retrieveOld($old_values, $primary_key);
$value = $values[$primary_key];
if (self::isCaseInsensitive($class, $primary_key) && fCore::stringlike($value) && fCore::stringlike($old_value)) {
if (self::isCaseInsensitive($class, $primary_key) && self::stringlike($value) && self::stringlike($old_value)) {
if (strtolower($value) != strtolower($old_value)) {
$different = TRUE;
}
Expand All @@ -524,7 +524,7 @@ static private function checkPrimaryKeys($object, &$values, &$old_values)
$sql = "SELECT " . join(', ', $primary_keys) . " FROM " . $table . " WHERE ";
$conditions = array();
foreach ($primary_keys as $primary_key) {
if (self::isCaseInsensitive($class, $primary_key) && fCore::stringlike($values[$primary_key])) {
if (self::isCaseInsensitive($class, $primary_key) && self::stringlike($values[$primary_key])) {
$conditions[] = 'LOWER(' . $primary_key . ')' . fORMDatabase::escapeBySchema($table, $primary_key, strtolower($values[$primary_key]), '=');
} else {
$conditions[] = $primary_key . fORMDatabase::escapeBySchema($table, $primary_key, $values[$primary_key], '=');
Expand Down Expand Up @@ -828,6 +828,22 @@ static private function sortMessageMatches($a, $b)
}


/**
* Returns `TRUE` for non-empty strings, numbers, objects, empty numbers and string-like numbers (such as `0`, `0.0`, `'0'`)
*
* @param mixed $value The value to check
* @return boolean If the value is string-like
*/
static private function stringlike($value)
{
if ((!is_string($value) && !is_object($value) && !is_numeric($value)) || !strlen(trim($value))) {
return FALSE;
}

return TRUE;
}


/**
* Validates values for an fActiveRecord object against the database schema and any additional validation rules that have been added
*
Expand Down
2 changes: 1 addition & 1 deletion classes/fTime.php
Expand Up @@ -62,7 +62,7 @@ public function __construct($time=NULL)
} else {
if (is_object($time) && is_callable(array($time, '__toString'))) {
$time = $time->__toString();
} elseif (fCore::stringlike($time)) {
} elseif (is_numeric($time) || is_object($time)) {
$time = (string) $time;
}
$timestamp = strtotime($time);
Expand Down
2 changes: 1 addition & 1 deletion classes/fTimestamp.php
Expand Up @@ -748,7 +748,7 @@ public function __construct($datetime=NULL, $timezone=NULL)
} else {
if (is_object($datetime) && is_callable(array($datetime, '__toString'))) {
$datetime = $datetime->__toString();
} elseif (fCore::stringlike($datetime)) {
} elseif (is_numeric($datetime) || is_object($datetime)) {
$datetime = (string) $datetime;
}
$timestamp = strtotime(self::fixISOWeek($datetime) . ' ' . $timezone);
Expand Down

0 comments on commit ec66b71

Please sign in to comment.