I used Symfony version v4.4.1 . I create project in CLI using symfony command:
symfony new my_project_name --full
But my folder in src/Controller is empty, please, help.
Maybe my Controllers are created in another directory. On screenshot, you can see trouble.
Early, it's working nice.
When you create a new application Controller directory is empty. It's a normal result when you use the full argument. Full will only specified that you have all common utilities/libraries (twig, security, etc). But you have to create your own business (entities, controllers, forms, views, etc).
If you want to create a Controller, you should install the maker bundle
symfony composer req maker --dev
Then the console will be able to create Controller as easy as:
symfony console make:controller MyNewController
Default controller is no longer in the empty application, because some applications do not need them. As example, if you are developing an API, you do not use controller. Another example, some developers do not use MVC(model view controller) pattern but the ADR (Action Domain Responder) Pattern
Related
after these commands
php artisan make:model 'FileName' -mcs
Laravel make command files sources (Model, Controller, Migration, Seeder, Factory etc...)
How all basic files generate and where from these files comes?
All the generated stuff in Laravel use templates
If you run artisan command in your console, you can observe that exists a section called stub, and the only command in this section is php artisan stub:publish.
If you run that command it will generate a new folder inn your app root folder called stubs with a bunch of files inside all with extension .stub.
You can open those files and modify then or customize them as needed. From now on this folder will be the place from where your Laravel app will read the template for making all kind of stuff that artisan usually does.
This templates are included with every Laravel installation and is totally optional publish them or not. In fact there are many packages dedicated to make custom Controllers or Models like this one from Spatie
The internals above this generators
Laravel has two kernels,
The first one in app/Console/kernel
The second one in app/Http/kernel
When you run artisan, Laravel Bootstrap the app, and run the Kernel console. This both Kernels has different purposes, really they function as separates apps.
About the specific generation of the above files, I mean different controllers, Models, migrations etc.. all that stuff related to models are generated by one Class.
class ModelMakeCommand extends GeneratorCommand{ .... }
Which is located under Illuminate\Foundation\Console namespace.
You can check the code of that class and see how the stubs files are used to generate the variety of commands only related to Models, but there are many more, like Policies, Events, Jobs etc...
I hope this helps and answer your question
Here you are more information about this subject from Laravel News
These files are being generated from stub files. Here are some stubs directory location on any laravel project. you can check this out.
For Model :
vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/model.stub
Others :
vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs
vendor/laravel/framework/src/Illuminate/Routing/Console/stubs
vendor/laravel/framework/src/Illuminate/Database/Console/Factories/stubs
vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/stubs
if you want control over these stubs you have to apply below command
php artisan stub:publish
this command will publish stub files on "stubs" folder on your project directory. Then you can customize according to your need.
I have my own Admin Bundle which is being developed in time. I just put it into new project and use it. If I need a new functionality I add it and use it later in another project. I put it in src/ directory. I don't want to store in on public Git repository.
Now as Symfony 4 is bundle-less, how should I easly put it into src/ dir so that it is decoupled from other App code?
I would like to develop the App as I shoulg but I would like to have an opportunity to easly copy Admin code to use it for another project.
Bundles are still perfectly available and useful in Symfony 4. They aren't suggested to be used for the main program code, as it is a little easier to not need that structure.
3rd party bundles are still incredibly useful though, to easily connect functionality, templates and services to an application. Equally, if you have some code that can be used in multiple applications and most easily added as a bundle, you are perfectly able to write your code as its own bundle. You can initially write it within your src/ directory, and then migrate it out to be an external bundle/library that can be pulled in via Composer when it's useful to do so.
I have a new symfony project. By default it contains
-/AppBundle
-AppBundle.php
--/Controller
--/Default Controller
Since I am going to have more bundles I would like it to be under a VendorName called MyProject where I have my ApiBundle.
I have tried moving AppBundle manually, then changing namespaces in the files, yml files and AppKernel. But I still get an error
Expected to find class "AppBundle\AppBundle" in file "/Applications/MAMP/htdocs/healthy-living/src/HealthyLiving/AppBundle/AppBundle.php" while importing services from resource "../../src/HealthyLiving/AppBundle/*", but it was not found! Check the namespace prefix used with the resource.' in /Applications/MAMP/htdocs/healthy-living/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php:133
Is there any console commands for doing this, if not what should be the procedures of moving it.
Thanks in advance
There's no console command or procedure to do it because it's not what vendor folder was designed for. vendor folder is meant to store 3rd-party code so keeping your own bundles, which you are developing, in vendor is not a good idea.
Since I am going to have more bundles
There is no reason that you can't keep more than one bundle inside your src folder. In fact, when Symfony introduced Bundle system it was very common that src folder contained a lot of bundles.
(note that vendor folder is almost always added to .gitignore - that's because what I wrote before)
EDIT after clarifying what the question is about:
It looks like command to generate bundles has/had some issues with creating bundles without Vendor folder:
Issue
Pull request
I don't know which version of Symfony are you using but either way creating bundle manually is always a good idea and it solves your problem too. (you can create it without vendor name)
You can upload your API bundle to a repository (Github, Gitlab, Bitbucket, etc.) and then import it as an external dependency with Composer.
Since moving was too complicated because of the config files that has to be changed so I decided to do a workaround and remove it and then install via console under the same parent. Works like a charm. Althoug could be a method in cli for this.
I'm a bit confused about where something like this belongs to Laravel.
I want to write a web service client wrapper in laravel, and I want to access it like this:
\MyWSClient::getSomeInfoAbout($someId);
then the code will connect to the web service to http://www.someapi.com/api/getSomeInfoAbout?id=$someid&type=json with OAuth2 or some token requests, then fetch the data, keep token information until it expires, refresh token if needed etc.
But where will I put the code? In the vendor directory as a new package? I'm moving this code from a computer to another computer except vendor,storage and node_modules folders, because they are huge and when I do this, I will have to move only one folder in the vendor directory. And I'll need to publish a package under development to composer if I want portability etc.
Is there any other way to do something like this?
I think I've found the answer.
First I needed to use jeroen-g/laravel-packager package to create a new package using artisan console. I could've done that by hand, but I didn't know the required files.
Second, I've created a new package in the packages folder with my desired class name.
Third, I've added the provider and the alias for the class in app.php.
After that, I've created a test method in my controller and wrote a route for that. I called the static method I've written in the SkeletonClass the packager created for me.
And it worked with some tweaking after creation.
I've used php artisan packager:new tpaksu mypackage --i command for an interactive package creation which is cool.
Note: I've just learned the existence of this package, I'm not advertising it :)
If I want to use some custom class in Lumen, where should I place them? The Laravel official document does not mention this in any of application structure, service container or package development. Actually I found the document quite confusing to some extents.
For example, I want to set up a service called Invitation, I know I need to register this class in InvitationServiceProvider but where should I place the Invitation.php which the actual class exists in? This package is used for some specific application thus I do not want to put it in composer packagist.
BTW, the version of Lumen Framework is 5.2.
So finally I created a folder named Service under app and just pull all the libraries inside...