I am trying to deploy a Yii2 app that consumes OData services. But I am having a bit problem: I choose https://github.com/saintsystems/odata-client-php (OData Client library from SaintSystems), I installed with composer and there was no complain. But when I use instantiate the objects it says:
$odataClient = new ODataClient($odataServiceUrl);
Then
Error
Class 'app\controllers\ODataClient' not found
And if
$odataClient = new \SaintSystems\OData\ODataClient($odataServiceUrl);
Then it complains with:
Call to undefined method SaintSystems\OData\Query\Builder::post()
So I think Yii 2 is not recognizing the namespaces or composer does not set them up correctly. How could I make yii2 take this namespace and I deploy successfully with this library.
Thank you all!
Related
I am developing some composer php library.
And I want to provide library users to use class that uses some external package. I suggest this package in the relevant composer section.
Should I check that the composer's suggested package is really installed?
Will there be an error if the user just install my library without suggestions, but will not use this class that dependent from not installed package?
I checked some popular packages and seems to be they just use suggested packages as if they are already installed.
For example: https://github.com/Seldaek/monolog/blob/c861fcba2ca29404dc9e617eedd9eff4616986b8/src/Monolog/Handler/ElasticsearchHandler.php
This monolog class just uses Elasticsearch classes as usual, but Elasticsearch is a suggested package and may be not installed.
The handlers use the other packages as if they were installed - but keep in mind that Monolog does not use each and every handler automatically. If you define that such a handler (in your example: the one for ElasticSearch) is used, it is up to the user to know how to handle this.
As you can see in the constructor of that method, it is not even instantiable if you don't have a package for ElasticSearch installed - the code example in that class helps to understand this situation. So, no, this class is not usable without having another package installed, but the error will be thrown by your classloader. No need for the package to check for this
I'm currently developing a set of packages/service providers to use as a sort of boilerplate for new web applications. I started developing some time ago and I never ran the packages through composer.
After I made a repository and added the package to a new Laravel application, it installed just fine, until it ran php artisan package:discover. The error was:
In breadcrumbs.php line 5:
Class 'Athena' not found
and it refers to this line:
Breadcrumbs::register( \Athena::getFacadeRoot()->route_name_prefix . '.dashboard.show', function ( $breadcrumbs ) {
in which \Athena:: is a facade within the package. I fixed the issue by adding the facade to the app.php file. The idea was to bootstrap applications easily, so my question is:
Can I use a facade within a package and still use the Laravel package discovery, without having to edit files when I create a new project?
I am trying to get my head around Composer. I want to integrate this package into my app: https://github.com/thiagoalessio/tesseract-ocr-for-php
I have done the following so far:
composer require thiagoalessio/tesseract_ocr
composer dump-autoload
and I have used the library within a Controller method as such:
$tesseract = new TesseractOCR($url);
But I'm getting the dreaded:
Class 'App\Http\Controllers\TesseractOCR' not found
How do I make sure that composer autoloads the package and that it is available throughout the apps, for usage within controllers?
Sorry, newbie in Composer here..
Composer has auto-loaded the package, you’re just referencing the class name incorrectly.
TesseractOCR lives in the “global” namespace, so you need to import it:
use TesseractOCR;
You can then use it in your controllers etc as normal.
I'm trying to develop a custom package using "workbench". It's a simple package that will create a repository to consume a different API we have. I plan on injecting this repository into my controllers of my application. Anyway, I created the package using "workbench". This creates the service provider. The Laravel docs say to add the service provider to my "providers" array in app.config. I've done this, but when I run composer update, I get an error saying that the class is not found, specifically: PHP Fatal error: Class 'MyVendor\MyPackage\ServiceProvider not found in /.. .. .. ../laravel/vendor/framework/src/Illuminate/Foundation/ProviderRepository.php. I thought I followed the docs correctly, what am I missing?
Simply running composer install inside the workbench directory resolves this issue.
When executing
php artisan workbench user/asset
additional dependency(module) placed to
workbench/user/asset/vendor/illuminate/support.
Then framework autoload this module(illuminate/support) from workbench/user/asset/vendor/*, but i think it must load it from /vendor/laravel/framework/src/Illuminate/
So we have confusion here - some classes are loaded from framework(vendor/laravel/*) and some classes are loaded from workbench/[vendor]/[module]. Is that supposed to work that way? Or is it a bug?
Yes and No.
During development of your package it will work that way, because the whole structure is inside /workbench. It also helps you working in different versions of packages, develop using Laravel 4.1 while your app is still on 4.0.
After you finish working on your package, it's better to create a real Composer package. You can create a private one and then, yeah, once you install it via Composer it will be placed in /vendor.