Skip to content

Commit

Permalink
Buy plugin: Safer PHP namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Oct 20, 2024
1 parent 89bef81 commit 8ca6aa5
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 59 deletions.
11 changes: 7 additions & 4 deletions site/controllers/buy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

use Kirby\Buy\Product;
use Kirby\Buy\RevenueLimit;
use Kirby\Buy\Sale;
use Kirby\Cms\Page;

return function (Page $page) {
$sale = new Buy\Sale();
$sale = new Sale();

// expire the cache when the sale banner/prices change
$sale->expires();
Expand All @@ -13,14 +16,14 @@
krsort($discountsReversed);

return [
'basic' => Buy\Product::Basic,
'basic' => Product::Basic,
'countries' => option('countries'),
'discounts' => $discounts,
'discountsReversed' => $discountsReversed,
'donation' => option('buy.donation'),
'enterprise' => Buy\Product::Enterprise,
'enterprise' => Product::Enterprise,
'sale' => $sale,
'questions' => $page->find('answers')->children(),
'revenueLimit' => Buy\RevenueLimit::approximation(verbose: true),
'revenueLimit' => RevenueLimit::approximation(verbose: true),
];
};
6 changes: 3 additions & 3 deletions site/controllers/partners-signup.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Buy\Paddle;
use Buy\Passthrough;
use Buy\Product;
use Kirby\Buy\Paddle;
use Kirby\Buy\Passthrough;
use Kirby\Buy\Product;
use Kirby\Cms\App;
use Kirby\Cms\Page;
use Kirby\Honey\Time;
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"autoload": {
"psr-4": {
"Buy\\": "src/"
"Kirby\\Buy\\": "src/"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Buy\RevenueLimit;
use Kirby\Buy\RevenueLimit;
use Kirby\Cms\App;

@include_once __DIR__ . '/vendor/autoload.php';
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Paddle.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

use Exception;
use Kirby\Http\Remote;
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Passthrough.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

use Kirby\Toolkit\Str;

Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Price.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

use Exception;
use Kirby\Toolkit\A;
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Product.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

enum Product: string
{
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/RevenueLimit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

class RevenueLimit
{
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Sale.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

use DateTime;
use DateTimeZone;
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Upgrade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

class Upgrade
{
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/src/Visitor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Buy;
namespace Kirby\Buy;

use Kirby\Cms\App;
use Kirby\Toolkit\Str;
Expand Down
20 changes: 8 additions & 12 deletions site/plugins/buy/vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
$baseDir = dirname($vendorDir);

return array(
'Buy\\Paddle' => $baseDir . '/src/Paddle.php',
'Buy\\Passthrough' => $baseDir . '/src/Passthrough.php',
'Buy\\Price' => $baseDir . '/src/Price.php',
'Buy\\Product' => $baseDir . '/src/Product.php',
'Buy\\RevenueLimit' => $baseDir . '/src/RevenueLimit.php',
'Buy\\Sale' => $baseDir . '/src/Sale.php',
'Buy\\Upgrade' => $baseDir . '/src/Upgrade.php',
'Buy\\Visitor' => $baseDir . '/src/Visitor.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'Kirby\\ComposerInstaller\\CmsInstaller' => $vendorDir . '/getkirby/composer-installer/src/ComposerInstaller/CmsInstaller.php',
'Kirby\\ComposerInstaller\\Installer' => $vendorDir . '/getkirby/composer-installer/src/ComposerInstaller/Installer.php',
'Kirby\\ComposerInstaller\\Plugin' => $vendorDir . '/getkirby/composer-installer/src/ComposerInstaller/Plugin.php',
'Kirby\\ComposerInstaller\\PluginInstaller' => $vendorDir . '/getkirby/composer-installer/src/ComposerInstaller/PluginInstaller.php',
'Kirby\\Buy\\Paddle' => $baseDir . '/src/Paddle.php',
'Kirby\\Buy\\Passthrough' => $baseDir . '/src/Passthrough.php',
'Kirby\\Buy\\Price' => $baseDir . '/src/Price.php',
'Kirby\\Buy\\Product' => $baseDir . '/src/Product.php',
'Kirby\\Buy\\RevenueLimit' => $baseDir . '/src/RevenueLimit.php',
'Kirby\\Buy\\Sale' => $baseDir . '/src/Sale.php',
'Kirby\\Buy\\Upgrade' => $baseDir . '/src/Upgrade.php',
'Kirby\\Buy\\Visitor' => $baseDir . '/src/Visitor.php',
'MaxMind\\Db\\Reader' => $vendorDir . '/maxmind-db/reader/src/MaxMind/Db/Reader.php',
'MaxMind\\Db\\Reader\\Decoder' => $vendorDir . '/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php',
'MaxMind\\Db\\Reader\\InvalidDatabaseException' => $vendorDir . '/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php',
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/buy/vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

return array(
'MaxMind\\Db\\' => array($vendorDir . '/maxmind-db/reader/src/MaxMind/Db'),
'Kirby\\Buy\\' => array($baseDir . '/src'),
'Kirby\\' => array($vendorDir . '/getkirby/composer-installer/src'),
'Buy\\' => array($baseDir . '/src'),
);
33 changes: 13 additions & 20 deletions site/plugins/buy/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,36 @@ class ComposerStaticInita859f2d2dfe8ca8f08832a211f59fd27
),
'K' =>
array (
'Kirby\\Buy\\' => 10,
'Kirby\\' => 6,
),
'B' =>
array (
'Buy\\' => 4,
),
);

public static $prefixDirsPsr4 = array (
'MaxMind\\Db\\' =>
array (
0 => __DIR__ . '/..' . '/maxmind-db/reader/src/MaxMind/Db',
),
'Kirby\\' =>
'Kirby\\Buy\\' =>
array (
0 => __DIR__ . '/..' . '/getkirby/composer-installer/src',
0 => __DIR__ . '/../..' . '/src',
),
'Buy\\' =>
'Kirby\\' =>
array (
0 => __DIR__ . '/../..' . '/src',
0 => __DIR__ . '/..' . '/getkirby/composer-installer/src',
),
);

public static $classMap = array (
'Buy\\Paddle' => __DIR__ . '/../..' . '/src/Paddle.php',
'Buy\\Passthrough' => __DIR__ . '/../..' . '/src/Passthrough.php',
'Buy\\Price' => __DIR__ . '/../..' . '/src/Price.php',
'Buy\\Product' => __DIR__ . '/../..' . '/src/Product.php',
'Buy\\RevenueLimit' => __DIR__ . '/../..' . '/src/RevenueLimit.php',
'Buy\\Sale' => __DIR__ . '/../..' . '/src/Sale.php',
'Buy\\Upgrade' => __DIR__ . '/../..' . '/src/Upgrade.php',
'Buy\\Visitor' => __DIR__ . '/../..' . '/src/Visitor.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'Kirby\\ComposerInstaller\\CmsInstaller' => __DIR__ . '/..' . '/getkirby/composer-installer/src/ComposerInstaller/CmsInstaller.php',
'Kirby\\ComposerInstaller\\Installer' => __DIR__ . '/..' . '/getkirby/composer-installer/src/ComposerInstaller/Installer.php',
'Kirby\\ComposerInstaller\\Plugin' => __DIR__ . '/..' . '/getkirby/composer-installer/src/ComposerInstaller/Plugin.php',
'Kirby\\ComposerInstaller\\PluginInstaller' => __DIR__ . '/..' . '/getkirby/composer-installer/src/ComposerInstaller/PluginInstaller.php',
'Kirby\\Buy\\Paddle' => __DIR__ . '/../..' . '/src/Paddle.php',
'Kirby\\Buy\\Passthrough' => __DIR__ . '/../..' . '/src/Passthrough.php',
'Kirby\\Buy\\Price' => __DIR__ . '/../..' . '/src/Price.php',
'Kirby\\Buy\\Product' => __DIR__ . '/../..' . '/src/Product.php',
'Kirby\\Buy\\RevenueLimit' => __DIR__ . '/../..' . '/src/RevenueLimit.php',
'Kirby\\Buy\\Sale' => __DIR__ . '/../..' . '/src/Sale.php',
'Kirby\\Buy\\Upgrade' => __DIR__ . '/../..' . '/src/Upgrade.php',
'Kirby\\Buy\\Visitor' => __DIR__ . '/../..' . '/src/Visitor.php',
'MaxMind\\Db\\Reader' => __DIR__ . '/..' . '/maxmind-db/reader/src/MaxMind/Db/Reader.php',
'MaxMind\\Db\\Reader\\Decoder' => __DIR__ . '/..' . '/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php',
'MaxMind\\Db\\Reader\\InvalidDatabaseException' => __DIR__ . '/..' . '/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php',
Expand Down
4 changes: 2 additions & 2 deletions site/plugins/buy/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'getkirby/buy',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '4f3641a2bd4d4f422f464e9cb7797114877abf5d',
'reference' => '5e80eb4dd91ec531a6d9373a74fe4da28c2738d1',
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'getkirby/buy' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '4f3641a2bd4d4f422f464e9cb7797114877abf5d',
'reference' => '5e80eb4dd91ec531a6d9373a74fe4da28c2738d1',
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down
6 changes: 3 additions & 3 deletions site/routes/buy.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Buy\Paddle;
use Buy\Passthrough;
use Buy\Product;
use Kirby\Buy\Paddle;
use Kirby\Buy\Passthrough;
use Kirby\Buy\Product;
use Kirby\Http\Response;

return [
Expand Down
4 changes: 2 additions & 2 deletions site/routes/partners.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Buy\Paddle;
use Buy\Product;
use Kirby\Buy\Paddle;
use Kirby\Buy\Product;
use Kirby\Honey\Time;
use Kirby\Http\Response;

Expand Down
2 changes: 1 addition & 1 deletion site/snippets/layouts/sale.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$sale = new Buy\Sale();
$sale = new Kirby\Buy\Sale();
?>

<?php if ($page->id() !== 'buy' && $sale->isActive() === true): ?>
Expand Down
2 changes: 1 addition & 1 deletion site/snippets/templates/buy/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
per site
</a>

<?php if ($product === Buy\Product::Basic): ?>
<?php if ($product === Kirby\Buy\Product::Basic): ?>
<details class="revenue text-sm color-gray-700">
<summary><?= $description ?> <mark><?= $limit ?> &rarr;</mark></summary>
<div>
Expand Down

0 comments on commit 8ca6aa5

Please sign in to comment.