mirror of
https://github.com/flextype/flextype.git
synced 2025-08-10 07:06:45 +02:00
Code cleanup and refactoring #5
This commit is contained in:
@@ -65,7 +65,7 @@ class Config
|
||||
* @param string $key Key
|
||||
* @param mixed $value Value
|
||||
*/
|
||||
public static function set($key, $value)
|
||||
public static function set($key, $value) : void
|
||||
{
|
||||
Arr::set(static::$config, $key, $value);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class Config
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public static function getConfig()
|
||||
public static function getConfig() : array
|
||||
{
|
||||
return static::$config;
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Arr;
|
||||
@@ -43,8 +43,9 @@ class Events
|
||||
* @param mixed $added_function Added function
|
||||
* @param integer $priority Priority. Default is 10
|
||||
* @param array $args Arguments
|
||||
* @return void
|
||||
*/
|
||||
public static function addListener(string $event_name, $added_function, int $priority = 10, array $args = null)
|
||||
public static function addListener(string $event_name, $added_function, int $priority = 10, array $args = null) : void
|
||||
{
|
||||
// Hooks a function on to a specific event.
|
||||
static::$events[] = array(
|
||||
|
@@ -28,7 +28,6 @@ class Filters
|
||||
*/
|
||||
protected static $filters = [];
|
||||
|
||||
|
||||
/**
|
||||
* Protected constructor since this is a static class.
|
||||
*
|
||||
@@ -39,6 +38,41 @@ class Filters
|
||||
// Nothing here
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filter
|
||||
*
|
||||
* @access public
|
||||
* @param string $filter_name The name of the filter to hook the $function_to_add to.
|
||||
* @param string $function_to_add The name of the function to be called when the filter is applied.
|
||||
* @param integer $priority Function to add priority - default is 10.
|
||||
* @param integer $accepted_args The number of arguments the function accept default is 1.
|
||||
* @return bool
|
||||
*/
|
||||
public static function addListener($filter_name, $function_to_add, $priority = 10, $accepted_args = 1) : bool
|
||||
{
|
||||
// Redefine arguments
|
||||
$filter_name = (string) $filter_name;
|
||||
$function_to_add = $function_to_add;
|
||||
$priority = (int) $priority;
|
||||
$accepted_args = (int) $accepted_args;
|
||||
|
||||
// Check that we don't already have the same filter at the same priority. Thanks to WP :)
|
||||
if (isset(static::$filters[$filter_name]["$priority"])) {
|
||||
foreach (static::$filters[$filter_name]["$priority"] as $filter) {
|
||||
if ($filter['function'] == $function_to_add) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static::$filters[$filter_name]["$priority"][] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
|
||||
|
||||
// Sort
|
||||
ksort(static::$filters[$filter_name]["$priority"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch filters
|
||||
*
|
||||
@@ -77,39 +111,4 @@ class Filters
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filter
|
||||
*
|
||||
* @access public
|
||||
* @param string $filter_name The name of the filter to hook the $function_to_add to.
|
||||
* @param string $function_to_add The name of the function to be called when the filter is applied.
|
||||
* @param integer $priority Function to add priority - default is 10.
|
||||
* @param integer $accepted_args The number of arguments the function accept default is 1.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addListener($filter_name, $function_to_add, $priority = 10, $accepted_args = 1)
|
||||
{
|
||||
// Redefine arguments
|
||||
$filter_name = (string) $filter_name;
|
||||
$function_to_add = $function_to_add;
|
||||
$priority = (int) $priority;
|
||||
$accepted_args = (int) $accepted_args;
|
||||
|
||||
// Check that we don't already have the same filter at the same priority. Thanks to WP :)
|
||||
if (isset(static::$filters[$filter_name]["$priority"])) {
|
||||
foreach (static::$filters[$filter_name]["$priority"] as $filter) {
|
||||
if ($filter['function'] == $function_to_add) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static::$filters[$filter_name]["$priority"][] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
|
||||
|
||||
// Sort
|
||||
ksort(static::$filters[$filter_name]["$priority"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -12,8 +12,7 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\{Filesystem\Filesystem, Finder\Finder};
|
||||
use Url;
|
||||
use Session;
|
||||
|
||||
@@ -30,7 +29,7 @@ class Flextype
|
||||
/**
|
||||
* Filesystem object
|
||||
*
|
||||
* @var object
|
||||
* @var Filesystem
|
||||
* @access public
|
||||
*/
|
||||
public static $filesystem = null;
|
||||
@@ -38,7 +37,7 @@ class Flextype
|
||||
/**
|
||||
* Finder object
|
||||
*
|
||||
* @var object
|
||||
* @var Finder
|
||||
* @access public
|
||||
*/
|
||||
public static $finder = null;
|
||||
@@ -75,7 +74,7 @@ class Flextype
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected static function app()
|
||||
protected static function app() : void
|
||||
{
|
||||
// Init Finder
|
||||
static::$finder = new Finder();
|
||||
@@ -140,9 +139,9 @@ class Flextype
|
||||
* Returns filesystem object
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
* @return Filesystem
|
||||
*/
|
||||
public static function filesystem()
|
||||
public static function filesystem() : Filesystem
|
||||
{
|
||||
return static::$filesystem;
|
||||
}
|
||||
@@ -151,9 +150,9 @@ class Flextype
|
||||
* Returns finder object
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
* @return Finder
|
||||
*/
|
||||
public static function finder()
|
||||
public static function finder() : Finder
|
||||
{
|
||||
return static::$finder;
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ use Symfony\Component\Yaml\Yaml;
|
||||
class I18n
|
||||
{
|
||||
/**
|
||||
* An instance of the Cache class
|
||||
* An instance of the I18n class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
|
@@ -20,7 +20,7 @@ class Markdown
|
||||
* Parsedown Extra Object
|
||||
*
|
||||
* @var object
|
||||
* @access protected
|
||||
* @access protected
|
||||
*/
|
||||
protected static $markdown;
|
||||
|
||||
|
@@ -27,7 +27,6 @@ class Plugins
|
||||
* Init Plugins
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
|
@@ -52,7 +52,7 @@ class Shortcodes
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public static function driver()
|
||||
public static function driver() : ShortcodeFacade
|
||||
{
|
||||
return static::$driver;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class Shortcodes
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected static function registerDefaultShortcodes()
|
||||
protected static function registerDefaultShortcodes() : void
|
||||
{
|
||||
static::driver()->addHandler('site_url', function() {
|
||||
return Url::getBase();
|
||||
|
Reference in New Issue
Block a user