Skip to content

Commit

Permalink
Update Cookie and MaxlengthTrait classes
Browse files Browse the repository at this point in the history
Updated the Cookie and MaxlengthTrait classes in TypeRocket core. In Cookie class, removed hard-coded null values for the `domain` parameter in setcookie function calls, and properly imported ErrorCollection class. In MaxlengthTrait, adjusted the getMaxlength method to accept null values and to correctly handle casting and string length calculation.
  • Loading branch information
kevindees committed Jul 2, 2024
1 parent 43e1b0c commit 2b1f867
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Elements/Traits/MaxlengthTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public function maxlength($length)
/**
* Get the max length for text type fields
*
* @param string $value
* @param string|null $value
* @param string $maxLength
*
* @return string|\TypeRocket\Html\Html
*/
public function getMaxlength( $value, $maxLength )
public function getMaxlength($value, $maxLength)
{
$max = '';

if ( $maxLength != null && $maxLength > 0) {
$left = ( (int) $maxLength ) - mb_strlen( $value );
$left = ( (int) $maxLength ) - mb_strlen( (string) $value );
$max = Html::p(['class' => 'tr-maxlength'], 'Characters left: ')->nest(Html::span($left));
}

Expand Down
7 changes: 4 additions & 3 deletions src/Http/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use TypeRocket\Utility\Data;
use TypeRocket\Utility\Sanitize;
use \TypeRocket\Http\ErrorCollection;

class Cookie
{
Expand Down Expand Up @@ -98,7 +99,7 @@ public function set( $name, $data, $time = MINUTE_IN_SECONDS, $path = '/' ) {
setcookie($name, $data, apply_filters('typerocket_cookie_options', [
'expires' => $time === null ? 0 : time() + $time,
'path' => $path,
'domain' => null,
'domain' => '',
'secure' => is_ssl()
], $name, $data, $this));

Expand Down Expand Up @@ -140,7 +141,7 @@ public function delete( $name, $path = '/' ) {
throw new \Exception('Cookie name is required to delete. You provided an empty string or null.');
}

setcookie($name, "", time() - 36000, $path, null, is_ssl());
setcookie($name, "", time() - 36000, $path, '', is_ssl());

return $this;
}
Expand Down Expand Up @@ -224,7 +225,7 @@ public function redirectMessage($default = null, $delete = true)
*/
function redirectErrors($default = null)
{
$errors = \TypeRocket\Http\ErrorCollection::getFromRuntimeCache();
$errors = ErrorCollection::getFromRuntimeCache();
return !is_null($errors) ? $errors->errors() : $default;
}

Expand Down

0 comments on commit 2b1f867

Please sign in to comment.