Пример #1
0
 public static function makeTimestampPhpSafe($timestamp = null)
 {
     // if timestamp comes in as a float, it'll be translated to, e.g. 1.30152466512E+13
     // and casting it to an int will not give us the original number
     if ($timestamp) {
         ToppaFunctions::throwExceptionIfNotString($timestamp);
     }
     switch (strlen($timestamp)) {
         case 14:
             $timestamp = substr($timestamp, 0, 11);
             break;
         case 13:
             $timestamp = substr($timestamp, 0, 10);
             break;
         case 12:
             $timestamp = substr($timestamp, 0, 9);
             break;
         case 11:
             $timestamp = substr($timestamp, 0, 8);
             break;
         case 0:
             $timestamp = 0;
             break;
         default:
             $timestamp = $timestamp;
     }
     return $timestamp;
 }
Пример #2
0
 public function testThrowExceptionIfNotArray()
 {
     $anArray = array('hello world');
     $this->assertTrue(ToppaFunctions::throwExceptionIfNotArray($anArray));
     try {
         $aNumber = 5;
         ToppaFunctions::throwExceptionIfNotArray($aNumber);
     } catch (Exception $e) {
         $this->pass();
     }
     try {
         $aString = 'hello, world';
         $this->assertTrue(ToppaFunctions::throwExceptionIfNotArray($aString));
     } catch (Exception $e) {
         $this->pass();
     }
 }
Пример #3
0
 public function generateSqlDeleteStatement($tableName, array $whereKeysAndValues)
 {
     ToppaFunctions::throwExceptionIfNotString($tableName);
     ToppaFunctions::throwExceptionIfNotArray($whereKeysAndValues);
     $sql = "delete from {$tableName} where ";
     array_walk($whereKeysAndValues, array($this, 'sqlEscapeCallback'));
     foreach ($whereKeysAndValues as $k => $v) {
         $sql .= "{$k} = {$v} and ";
     }
     $sql = substr($sql, 0, -5);
     $sql .= ";";
     return $sql;
 }