I have an laravel application and I need to install this package lunar-calendar
I install it and the package shows in vendor folder:
The package documentation tells to required the package like this:
use yzha5\LunarCalendar;
I put this way but also try this in controller:
use App\yzha5\LunarCalendar;
but returns not found.
I also run the command to publish vendor but doesn't work.
How can I use this package?
The package doesn't contain a service provider, so publish vendor will accomplish nothing really.
use yzha5\LunarCalendar;
\\ will not work because it isn't registered in your service provider that this alias equals the package path
use App\yzha5\LunarCalendar;
\\ will not work because there isn't a folder in app directory named yzha5.
Since it's just two classes and not exactly a decently build package, I'd just fetch those two files into a directory at your choosing, change the namespace and call them.
Related
I have tried to install telescope according to Jeffrey's video.
I am using the latest version of laravel. I have installed according to the laravel documentation for installing as dev.
But, don't get the file config/telescope.php and app\Providers\TelescopeServiceProviders.php in config folder.
Need to mention:
--I have used use Laravel\Telescope\TelescopeServiceProvider namespace in AppServiceProvider.php
We'd like to create a bundle which can deployed via composer/packagist for others to use. It'll wrap the logic created by the owners of MessageBird. Basically a kind of Service which will indeed be called with the container via ourvendor.messagebird.messaging.
Since it's a type of bundle (as per the docs of Sf3), we created a bundle while following the documentation:
http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html
As the directory /src we used /vendor instead. That's when it all went wrong. Our namespace could not be located, loaded or even when we manually added it to the autoloading classes of Composer it failed all the same.
The question is, what is the best practice to go about this? We got it working right now and what we did was the following:
We created a bundle wit the following cmd:
bin/console generate:bundle --shared --namespace=OurVendor/MessageBird/MessageBirdBundle --bundle-name=MessageBirdBundle --format=yml
We moved the /src/OurVendor directory to /vendor/OurVendor as the only way to get a perfect generation was to use the default /src folder.
We manually updated the AppKernel.php
We did some debugging with namespaces for Composer but eventually we added "OurVendor\\":"vendor/" to the "autoload/psr-4" directive in root composer.json
We ran composer dumpautoload && bin/console cache:clear -e dev which resulted in an error.
We ran composer -o update which checked all dependencies and updated accordingly, including autogenerated autoload files
Strangely enough we had to add the Bundle to the AppKernel.php class and cleaned the cache again.
After all this it worked but the documentation said no such thing about developing a 3rd party vendor bundle.
http://symfony.com/doc/current/bundles/best_practices.html
So long story short, did we go about it the wrong way or what?
/vendor directory is managed by composer. Do not copy/move anything there. Don't even edit anything there, unless you understand all consequences.
When you create a shared bundle, you need to push it to a VCS of your choice, and add it as a dependency in composer.json of the project which uses it.
When you run composer update it will check-out your bundle into /vendor directory and generate correct autoload file.
Please read more how to use private repositories with composer.
I am trying to develop a Laravel package with a helper function, which returns a view. I have uploaded on GitHub already https://github.com/faisalahsan/laravel-breadcrums. When I install it through Packagist https://packagist.org/packages/faisalahsanse/laravel-breadcrums, it installs successfully, but when I register it in the provider array in my app.php as Faisalahsanse\Breadcrums\BreadcumsServiceProvider::class,. It gives the following error:
Class 'Faisalahsanse\Breadcrums\BreadcumsServiceProvider' not found
I don't know where I am getting wrong.
Any suggestions?
Your namespace is wrong https://github.com/faisalahsan/laravel-breadcrums/blob/master/src/BreadcumsServiceProvider.php#L2
It should be Faisalahsan\LaravelBreadcrums. As this namespace you are adding in the composer.json file in psr-4 autoload.
Also your provider to add will be Faisalahsan\Breadcrums\BreadcumsServiceProvider::class
I'm trying to get some code set up to use an particular company's API.
I have experience with Perl and if I need a module installed, I type cpan ModuleName and most of the time it Just Works. How does that work with PHP code of similar complexity?
The company in question have a github repository with PHP Client system to access their API, which looks much the same as a perl Module.
I can git clone it, I can download it, but then what? Do I have to install it? There are no installation instructions. Or do I just start using it? There's a composer.json file in there. Do I need to run a composer command so it can figure out and install its dependencies like a CPAN module would? Will it install into system folders or just right there in whatever directory it happens to be in? I feel like there ought be some kind of official installation process because there's a /tests/ folder in the files I downloaded.
Their example code literally starts like this:
<?php
/* #var $CompanyName \CompanyName_Api */
$CompanyName = new \CompanyName_Api();
/* do interesting stuff */
and that's it. Of course nothing works if I just do that because it doesn't know where the CompanyName_Api files are. It works if I add this:
<?php
include('/full/path/to/downloaded/files/CompanyName/src/Api.php');
is that all I need to do?
In order to install all dependencies defined in composer.json you would run the following command inside the project directory:
composer install
This will find and download the dependencies into the vendor directory and it will also generate an optimized autoloader.
To autoload your own source files you'll need to add it to the autoload section in the composer.json file:
First your need to install an PHP environment like PHP, Apache and all stuff, then you need to clone that file from the git repository or just download it, then navigate to the dir and fire the command composer install. It will install all of the dependencies required for that package. After that, run the code from the browser -- the package api code may have the auto loader file which you need to include in your current package and autoloader will do all the stuff for you. Add your folder structure and file structure so that you get a better answer on this.
I'm using Laravel 4 and I want to use a third party package within this framework. I did this to install it:
1) Add package name to composer.json file
2) Run composer update command
Now I have package available in /vendors folder. My question is, how to use it inside the Laravel now?
Looking in the config/app.php file, I can not add it to "providers" array as far as I can see, nor "aliases".
When I try to instantiate that package class directly in controller I get the error "Class not found" ( I tried full name to the class: $pack = new /vendor/package.../class.php )
Any help on how to include and use the class in the laravel greatly appreciated
If the package provides a ServiceProvider, add it to app/config/app.php.
Otherwise composer has already took care of autoloading for you, so you just have to:
$package = new Package;
In the cases where the package is namespaced, you'll have to:
$package = new PackageNamespace\Package;
To be sure, take a look at the vendor/composer/autoload_* files, usually vendor/composer/autoload_classmap.php, search for the package name or class name and you'll see how it is named. Or just take a look at the main package souce file, usually in:
vendor/vendorName/packageName/[src or lib or whatever]/Package.php
EDIT
I just installed it here and did:
Route::get('test', function()
{
dd(new WideImage\WideImage);
});
Works like a charm. This package is in the 'namespaced' case I wrote above.