Skip to content

Commit

Permalink
Fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalguru committed Jan 28, 2023
1 parent 40b578e commit e07b6e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/TgUtils/DummyStringFilter.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

package TgUtils;
namespace TgUtils;

/**
* An interface for not filtering string at all.
*/
public class DummyStringFilter implements StringFilter {
class DummyStringFilter implements StringFilter {

public static $INSTANCE = new DummyStringFilter();
public static $INSTANCE;

public __construct() {
public function __construct() {
}

/**
* Filters the given string and returns sanitized value.
* @param string $s - string to sanitize (can be null)
* @return the sanitized string.
*/
public filter($s) {
public function filter($s) {
return $s;
}

}

DummyStringFilter::$INSTANCE = new DummyStringFilter();
11 changes: 6 additions & 5 deletions src/TgUtils/NoHtmlStringFilter.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?php

package TgUtils;
namespace TgUtils;

/**
* An interface for filter strings from any HTML tags.
*/
public class NoHtmlStringFilter implements StringFilter {
class NoHtmlStringFilter implements StringFilter {

public static $INSTANCE = new NoHtmlStringFilter();
public static $INSTANCE;

public __construct() {
public function __construct() {
}

/**
* Filters the given string and returns sanitized value.
* @param string $s - string to sanitize (can be null)
* @return the sanitized string.
*/
public filter($s) {
public function filter($s) {
if ($s == NULL) return $s;
return strip_tags($s);
}

}
NoHtmlStringFilter::$INSTANCE = new NoHtmlStringFilter();

4 changes: 2 additions & 2 deletions src/TgUtils/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function hasGetParam($key) {
*/
public function getGetParam($key, $default = NULL, $filter = NULL) {
$params = $this->getParams;
if ($filter == NULL) $filter = StringFilters::$NO_HTML;
if ($filter == NULL) $filter = NoHtmlStringFilter::$INSTANCE;
return isset($params[$key]) ? $filter->filter($params[$key]) : $default;
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public function hasPostParam($key) {
*/
public function getPostParam($key, $default = NULL, $filter = NULL) {
$params = $this->getPostParams();
if ($filter == NULL) $filter = StringFilters::$NO_HTML;
if ($filter == NULL) $filter = NoHtmlStringFilter::$INSTANCE;
return isset($params[$key]) ? $filter->filter($params[$key]) : $default;
}

Expand Down
6 changes: 3 additions & 3 deletions src/TgUtils/StringFilter.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

package TgUtils;
namespace TgUtils;

/**
* An interface for filter strings from evil input.
*/
public interface StringFilter {
interface StringFilter {

/**
* Filters the given string and returns sanitized value.
* @param string $s - string to sanitize (can be null)
* @return the sanitized string.
*/
public filter($s);
public function filter($s);

}

0 comments on commit e07b6e2

Please sign in to comment.