Skip to content

Commit

Permalink
publish
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobianco committed Apr 24, 2020
1 parent a5cedcf commit 079ffe0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javanile/granular",
"version": "0.0.10",
"version": "0.0.11",
"authors": [
{
"name": "Francesco Bianco",
Expand Down
13 changes: 4 additions & 9 deletions granular.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php
/**
* @version 0.0.10
*/
/*
Plugin Name: Granular
Plugin URI: https://github.com/javanile/granular
Expand All @@ -13,12 +10,10 @@

defined('ABSPATH') or exit;

require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';

$app = new Javanile\Granular\Autoload();
use Javanile\Granular\Autoload;

$app->autoload('Javanile\\Granular\\', __DIR__.'/src');
$app = new Autoload(null, __FILE__);

$app->bindings([
'action:init' => 'init'
]);
$app->autoload('Javanile\\Granular\\', __DIR__.'/src');
17 changes: 15 additions & 2 deletions src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ class Autoload
*/
protected $container;

/**
* WordPress plugin entrypoint file.
*
* @var ContainerInterface
*/
protected $entrypoint;

/**
* Autoload constructor.
*
* @param ContainerInterface|null $container
* @param string|null $entrypoint
*/
public function __construct(ContainerInterface $container = null)
public function __construct(ContainerInterface $container = null, $entrypoint = null)
{
$this->container = $container;
$this->entrypoint = $entrypoint;
}

/**
Expand Down Expand Up @@ -204,7 +213,11 @@ private function addMethodCallbackPlugin(array $tokens, Callback $callback, $met
return;
}

call_user_func_array($this->getFunction($function), [__FILE__, $callback->getMethodCallback($method)]);
if (!$this->entrypoint) {
return;
}

call_user_func_array($this->getFunction($function), [$this->entrypoint, $callback->getMethodCallback($method)]);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/AutoloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testBindMethod()

public function testRegisterClass()
{
$autoload = new Autoload(new FakeContainer);
$autoload = new Autoload(new FakeContainer, 'entrypoint');

$this->assertEquals(
['action:init' => ['init']],
Expand Down

0 comments on commit 079ffe0

Please sign in to comment.