Permalink
Browse files

BackwardsCompatibilityBreak - Removed fCore::stringlike()

  • Loading branch information...
wbond committed Nov 17, 2008
1 parent 843e4a0 commit ec66b7139d118c9c67faccf0fee8913a6e52215a
@@ -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];
}
}
View
@@ -29,7 +29,6 @@ class fCore
const handleException = 'fCore::handleException';
const reset = 'fCore::reset';
const sendMessagesOnShutdown = 'fCore::sendMessagesOnShutdown';
const stringlike = 'fCore::stringlike';
/**
@@ -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();
}
@@ -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
*
View
@@ -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));
View
@@ -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
*
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
);
@@ -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
View
@@ -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;
}
View
@@ -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;
}
View
@@ -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);
View
@@ -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;
}
@@ -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])) {
@@ -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])) {
View
@@ -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
View
@@ -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;
}
View
@@ -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;
}
@@ -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(
View
@@ -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;
}
@@ -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;
}
View
@@ -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;
}
@@ -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], '=');
@@ -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
*
View
@@ -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);
View
@@ -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);
Oops, something went wrong.

0 comments on commit ec66b71

Please sign in to comment.