joomla-framework / di Goto Github PK
View Code? Open in Web Editor NEWJoomla Framework DI Package
License: GNU General Public License v2.0
Joomla Framework DI Package
License: GNU General Public License v2.0
Some libraries require psr/container v2, but this component does not declare such compatibility. The only difference between v1 and v2 is that has()
now specifies a return type.
Line 503 in dfe260c
I was reviewing the deprecated messages in my Joomla 4 install and was confused by this one
2018-09-14T11:30:12+00:00 WARNING 127.0.0.1 deprecated Joomla\DI\Container::exists() is deprecated and will be removed in 3.0, use Psr\Container\ContainerInterface::has() instead.
So I came here to suggest that the message was clarified to include framework or similar so it was clearer when you hit the message in the CMS.
But then I discovered that the message doesn't exist here and the version of this file in my j4 install is completely different to this one??
For whatever reason, joomla/di
appears in the list of packages providing psr/container-implementation, and yet it does not: this package is not PSR-11 compatible in any way. I honestly have no idea how a package ends up on that list, but if it is under your control, I think it should be removed from that list.
Use Joomla\Container\Container::buildObject()
.
No notices.
Deprecated: Method ReflectionParameter::getClass() is deprecated in vendor\joomla\di\src\Container.php on line 324
PHP 8.0.2
Both branches affected.
What do you think about adding ContainerAwareTrait
with getContainer
and setContainer
methods?
I know it's PHP 5.4+ but there could be a not in the docblock.
The 2.0 branch already implements the Interop Container interface, which is what PSR-11 is based on. We should switch this to the PSR interface once the vote is complete and the package published and additionally try to implement it for the 1.x branch.
The buildObject
method uses set
method at the bottom.
In specific case this may lead to infinite loop of
Joomla\DI\Container->buildObject()
and Joomla\DI\Container->getMethodArgs()
methods resulting in
Fatal error: Maximum function nesting level of '100' reached, aborting!
Because same key is being set in two places at a time:
$fqcn = '\\Extension\\vendor\\FooComponent\\FooComponent';
$data = array();
$container->set(
$fqcn,
function (Container $c) use ($fqcn, $data)
{
$instance = $c->buildObject($fqcn);
$instance->setData($data);
return $instance;
}
);
I'm not sure if this is a bug (I'd say the set
method shouldn't be part of the buildObject
) or I misunderstood the functionality.
Use Joomla fw/ DI on my platform, install by composer
composer install "joomla/di"
Install without warning
There is a warning
Class Joomla\DI\Tests\StubInterface located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub1 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub2 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub3 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub4 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub5 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub6 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub7 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub8 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Class Joomla\DI\Tests\Stub9 located in ./vendor/joomla/di/Tests/Stubs/stubs.php does not comply with psr-4 autoloading standard. Skipping.
Docker container Debain 10
Nginx with PHP8
This just need to separate file into many files. Is there any deeper reason we keep them into one file ?
See the results of phan in 3.x-dev. In src/Container.php
line 467 and 483, the methods \ReflectionType::isBuiltin()
and \ReflectionType::getName()
are used, which don't exist in PHP 8 anymore. This needs to be refactored.
I propose adding an enumeration method (e.g. getIterator
) or implementing an enumeration interface (e.g. Iterator
) or other Traversable
interface (e.g. IteratorAggregate
) would be useful. My container factory dynamically generates services and I would like to be able to pull every service from the container at runtime by iterating each one. The specific implementation is up to you.
I propose an implementation similar to the following.
public function getIterator()
{
foreach ($this->aliases as $key) {
yield $key;
}
foreach ($this->resources as $key => $resource) {
yield $key;
}
}
There would presumably need to be some discussion around whether to include any $parent
s. I don't know what the use-case for parents is so I decline to comment.
DatabaseDriver
from the containerFatal error: Declaration of Joomla\DI\Container::has(string $resourceName) must be compatible with Psr\Container\ContainerInterface::has(string $id): bool in /libraries/vendor/joomla/di/src/Container.php on line 107
The DatabaseDriver
is loaded
A fatal error is thrown.
PHP 8.1/PHP 8.2
Joomla 5.0.2
The Container.php
has this line:
public function has($resourceName)
that should be changed to:
public function has(string $resourceName): bool
<?php
class joomla {
public function __construct() {
$this->loadJoomla();
$db = Factory::getContainer()->get('DatabaseDriver');
}
private function loadJoomla(): void
{
// Tell Joomla we can be trusted
if (!defined('_JEXEC'))
{
define('_JEXEC', 1);
}
// Set the base folder
$base = dirname(__FILE__, 7);
define('JDEBUG', false);
if (!defined('JPATH_BASE'))
{
define('JPATH_BASE', dirname($base));
}
if (file_exists($base . '/../includes/defines.php'))
{
require_once $base . '/../includes/defines.php';
}
require_once $base . '/bootstrap.php';
require_once JPATH_CONFIGURATION . '/configuration.php';
}
}
The extend()
method is typehinted to only allow a Closure
to be used for service decorators. This is inconsistent with the rest of the container which allows any callable to be used for a service. Let's make extend()
work with anything that is callable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.