Skip to content

Commit

Permalink
v2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbills committed Dec 5, 2024
1 parent 62cbe37 commit b1ecdbe
Show file tree
Hide file tree
Showing 24 changed files with 508 additions and 164 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_size = 4

[*.php]
charset = utf-8
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[*.{json, html, js, css}]
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/vendor/
/node_modules/
/wp-build/
*.zip
*.log
*.min.js
*.min.css
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## 2.3.5 - 2024-12-05

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/2.3.4...2.3.5)

- Tested up to WordPress 6.7
- Minor fixes

## 2.3.4 - 2024-08-26

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/2.3.3...2.3.4)
Expand Down
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
{
"require": {
"php": ">=7.4",
"ext-mbstring": "*"
},
"require-dev": {
"szepeviktor/phpstan-wordpress": "^1.1",
"php-stubs/woocommerce-stubs": "^7.4",
"phpstan/phpstan": "^1.10"
},
"scripts": {
"check": "phpstan",
"build": "./scripts/build",
"deploy": "./scripts/svn-push",
"update-trunk": "./scripts/svn-push --only-trunk",
"make-pot": "wp i18n make-pot . languages/wc-shipping-simulator.pot",
"upgrade-core": "./scripts/upgrade-core"
},
"autoload": {
"psr-4": {
"Shipping_Simulator\\": [
Expand All @@ -25,6 +18,17 @@
]
}
},
"config": {
"platform-check": false
},
"scripts": {
"build": "./scripts/build",
"deploy": "./scripts/svn-push",
"update-trunk": "./scripts/svn-push --only-trunk",
"make-pot": "wp i18n make-pot . languages/wc-shipping-simulator.pot",
"upgrade-core": "./scripts/upgrade-core",
"check": "phpstan"
},
"wp-plugin-base": {
"namespace": "Shipping_Simulator",
"text-domain": "wc-shipping-simulator"
Expand Down
43 changes: 22 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

defined( 'WPINC' ) || exit( 1 );
defined( 'ABSPATH' ) || exit( 1 );

return [
'SLUG' => 'wc-shipping-simulator',
'PREFIX' => 'wc_shipping_simulator_',
'LANGUAGES_DIR' => 'languages',
'TEMPLATES_DIR' => 'templates',
'DONATION_URL' => 'https://luizpb.com/donate/',
'PLUGIN_REVIEWS' => 'https://wordpress.org/support/plugin/shipping-simulator-for-woocommerce/reviews/?filter=5#new-post',
Expand Down
51 changes: 43 additions & 8 deletions core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@

namespace Shipping_Simulator\Core;

abstract class Config {
final class Config {
/** @var array */
protected static $values = [];

/**
* @param string $main_file The file that contains the plugin headers
* @return void
* @throws \Exception
*/
public static function init ( $main_file ) {
if ( self::get_size() > 0 ) {
throw new \Error( __CLASS__ . ' already initialized' );
throw new \Exception( __CLASS__ . ' already initialized' );
}

$root = dirname( $main_file );
$config = require $root . '/config.php';

if ( ! is_array( $config ) ) {
throw new \Error( $root . '/config.php must return an Array' );
throw new \Exception( $root . '/config.php must return an Array' );
}

if (
function_exists( 'wp_get_environment_type' )
&& in_array( \wp_get_environment_type(), [ 'local', 'development' ] )
&& file_exists( $root . '/config.dev.php' )
) {
$config_dev = include $root . '/config.dev.php';
$config = array_replace( $config, $config_dev );
}

foreach ( $config as $key => $value ) {
Expand All @@ -27,44 +42,64 @@ public static function init ( $main_file ) {

$slug = isset( self::$values[ 'SLUG' ] ) ? self::$values[ 'SLUG' ] : false;
if ( ! $slug || ! is_string( $slug ) ) {
throw new \Error( $root . '/config.php must define a string SLUG (Recommended: only alphanumeric and dashes)' );
throw new \Exception( $root . '/config.php must define a string SLUG (Recommended: only alphanumeric and dashes)' );
}

$prefix = isset( self::$values[ 'PREFIX' ] ) ? self::$values[ 'PREFIX' ] : false;
if ( ! $prefix || ! is_string( $prefix ) ) {
throw new \Error( $root . '/config.php must define a string PREFIX (only alphanumeric and underscores)' );
throw new \Exception( $root . '/config.php must define a string PREFIX (only alphanumeric and underscores)' );
}

self::$values[ 'FILE'] = $main_file;
self::$values[ 'DIR' ] = $root;

$data = \get_file_data( $main_file, [ 'Plugin Name', 'Version' ] );
self::$values[ 'NAME' ] = __( $data[0], 'wc-shipping-simulator' );
self::$values[ 'VERSION' ] = $data[1] ? $data[1] : '0.0.0';
self::$values[ 'VERSION' ] = $data[1] ? $data[1] : false;
}

/**
* @param string $key
* @param mixed $value
* @return mixed The value
* @throws \Exception
*/
public static function set ( $key, $value ) {
$key = mb_strtoupper( $key );
if ( isset( self::$values[ $key ] ) ) {
throw new \Error( __METHOD__ . ": Key \"$key\" has already been assigned. No key can be assigned more than once." );
throw new \Exception( __METHOD__ . ": Key \"$key\" has already been assigned. No key can be assigned more than once." );
}
self::$values[ $key ] = $value;
return $value;
}

/**
* @param string $key
* @param mixed $default
* @return mixed
* @throws \Exception
*/
public static function get ( $key, $default = null ) {
$key = \mb_strtoupper( $key );
$value = isset( self::$values[ $key ] ) ? self::$values[ $key ] : $default;
if ( null === $value ) {
throw new \Error( __METHOD__ . ": Undefined key $key" );
throw new \Exception( __METHOD__ . ": Undefined key $key" );
}
return $value;
}

/**
* @return int<0, max>
*/
public static function get_size () {
return count( self::$values );
}

/**
* @param string $string
* @param string $sep
* @return string
*/
public static function sanitize_slug ( $string, $sep = '-' ) {
$slug = \strtolower( \remove_accents( $string ) ); // Convert to ASCII
// Standard replacements
Expand Down
Loading

0 comments on commit b1ecdbe

Please sign in to comment.