D
D
Dmitry Kim2016-09-05 09:18:11
git
Dmitry Kim, 2016-09-05 09:18:11

How to get started with your github repository for yii2?

After writing 2-3 projects, a reasonable question arises - how to get rid of copying / pasting the necessary classes of helpers / widgets / assets, etc. from project to project and keep them up to date. The answer is asked by itself - through placement in the repository.
As I see this task for yii2:
We create our repository in the vendor folder, put the necessary files there, check that everything works, commit, in other projects we add our repository to composer.json.
Is this the right approach or not?
Problems:
If, for example, the folder structure of the repository is:
vendor/MYREPO/yii2-widgets/Toastr/Toastr.php
Then how to achieve the use of namespace MYREPO\Toastrin the file Toastr.php?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mitaichik, 2016-09-05
@kimono

There are several approaches, it all depends on the needs. I will not describe simple solutions, such as stupidly require from a shared folder, or add an autoloader, etc.
The main thing is that in the vendor folder we do not change anything with our hands and do not create anything there - it is controlled by the composer and the blade is not needed there.
The first variant is to create a git repository for the common code (it doesn’t matter where, even on our computer, even on the same github / bitbucket) and stupidly connect the repository. But this is a poor option.
The second (if the code is not private) - we do it like everyone else - we create a repository on github and regim the package in the packagist - the most standard way. From here all the pluses that come out, for example, version management.
The third one is the same, but for private code: we set up our composer server (for example, satis) - we get the same as composer + github, only a private version.
It should be noted that when you divide into packages, then your code will be developed in isolation from the projects where it is used. That is, it’s not like you wrote something in your library, updated the page of the main project - and everything was applied - no. You will need to commit, tag, push, update dependencies in the main project, etc. Therefore, I advise you to write a common code in absolute isolation from where it will be used (as a framework - its developers do not know where it will be used). To check the changes, I advise (if you are not already using it) to master automatic testing. It will be necessary to think over the interface of your lib much better. But in general, this is all a positive movement. So go ahead and good luck

T
Tema, 2016-09-05
@Tem_ka

Package your helpers in composer.json. Easy to connect and keep up-to-date, project-independent

If, for example, the folder structure of the repository is:
vendor/MYREPO/yii2-widgets/Toastr/Toastr.php
Then how do you get the namespace MYREPO\Toastr to be used in the Toastr.php file?

Write your own autoloader. In general, they have already suggested correctly, look at how libraries are doing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question