Im having problem with getting a custom interface to be found.
Could not resolve AddressBookEntryCache! Class "AddressBookEntryCache" does not exist. File: /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php
Above is the error I get. This is my code:
<?php
declare(strict_types=1);
use OCP\AppFramework\Http\DataResponse;
use OCP\Http\Client\IClientService;
class AddressBookEntryCache implements IAddressBookEntryCache
{
private static $cache;
private static int $timestamp;
private IClientService $clientService;
public function __construct(IClientService $clientService) {
$this->clientService = $clientService;
}
public function getCache(): DataResponse
{
return new DataResponse("insert logic here when things work");
}
}
<?php
declare(strict_types=1);
interface IAddressBookEntryCache {
public function getCache(): \OCP\AppFramework\Http\DataResponse;
}
<?php
declare(strict_types=1);
namespace OCA\SDK\AppInfo;
use AddressBookEntryCache;
use IAddressBookEntryCache;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Http\Client\IClientService;
use Psr\Container\ContainerInterface;
class Application extends App implements IBootstrap {
public const APP_ID = 'sdk';
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}
public function register(IRegistrationContext $context): void
{
$context->registerService(IAddressBookEntryCache::class, function (ContainerInterface $c): AddressBookEntryCache {
return new AddressBookEntryCache($c->get(IClientService::class));
});
/*$context->registerService(AddressBookEntryCache::class, function (ContainerInterface $c): AddressBookEntryCache {
return $c->get(AddressBookEntryCache::class);
});*/
$context->registerServiceAlias(IAddressBookEntryCache::class, AddressBookEntryCache::class);
}
public function boot(IBootContext $context): void
{
// TODO: Implement boot() method.
}
}
I’ve tried a couple things in Application.php, thats why it’s commented out, and in AddressBookEntryCache.php all the logic is commented out.
Thank you kind sir for your explanation.
It was the namespace I was missing. Would never figure that out myself (being new to PHP and no warning or error about it )
Thank you for a quick and well written summary. Noticed the project actually was using version 7.4, but when I type php --version I have PHP 8.1.2-1ubuntu2.14 (cli).
Is it just as easy to change in composer.json under
The setting in the composer just sets the compatibility level. So, if you had a newer PHP version, it will restrict the dependencies to those dependency versions that are in fact satisfying the (overridden) PHP version.
You are not setting the PHP version in some sense. It is just the version that is in use. Keep in mind, this is also true for the users of the app. So, if you would require a minimum PHP version of 8.0 that would be your decision to make your life easier and use the new features. You can mark this in the file app/info.xml that has a PHP version restriction. This will make the NC updater ignore this individual version from the app store if the PHP was not in the correct version present.
Short answer: You cannot enforce the PHP version you must be compatible with it.
As christianlupus said : you can use your current version of php. Composer inform users the version you should use. It’s not like npm for comparison.
One thing I want to add to this from my experience: Although 8.1 is the oldest supported PHP version today, you have to consider supporting even older ones. State right not is that LTS ubuntu (20.04 LTS) still has 7.4 as default PHP version until 2025! That means you might geht strange messages from users complaining about errors/warnings by their ancient PHP installations in the worst case and if you are not having a close eye on things.