When I worked with Spring MVC in Java , it manage all dependency by Maven and I think with Laravel , all library are managed by Composer. (I'm not sure, cause I'm a newbie in Laravel ^^ )
Now, I have 2 laravel project, one common project and one sub project , in sub project how can I use common project through Composer management ?
As mentioned by Pitchinnate, you can include a local repository via Composer.
You'll want to reference the second repository that the first is dependant upon in the "repositories" section of your composer.json, and then require it.
Ex:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*#dev"
}
}
This should allow you to link your project and sub-project, if we've understood your question correctly.
Cheers!
Related
First of all, I know this setup is stupid but this is what we're stuck with 🤷♂️
We build websites with our company framework. The website contains some classes that the framework directly accesses. This means we have a circular dependency. This was not a problem until now.
These are slimmer versions of our composer.jsons:
Framework:
The framework just defines some other
{
"name": "company/framework",
"type": "library",
"require": {
...
}
}
Website:
{
"name": "company/website",
"require": {
"company/framework": "^4.3",
...
}
}
Very simple, framework is a dependency of website.
Now, I'm trying to setup a CI server with static analysis for the framework. As mentioned, the framework requires some files in the website for static analysis to succeed.
The new company/framework/composer.json file looks like this:
{
"name": "company/framework",
"type": "library",
"require": {
"company/website": "^4.3",
...
}
}
This works fine when testing a tagged framework version. Whenever we're in a develop branch Composer will fail since website requires a stable ^4.3 version of the framework but this is a develop branch.
Is there any way I can work around this?
Extract the classes that are needed to test the framework into a separate package.
Framework requires that package.
Website requires that package. And requires Framework (which also requires that package).
Voila, you transformed a circular dependency into a linear graph.
Add semantic versioning to this approach, and you will never have serious problems - or spot them pretty soon.
We currently have Yii2 base project (we can say, like, project root from which we will create other projects). Right now there are several modules, models, controllers and viewers. Everything is fine here but how to deploy (and where) so that when we update base project, all child projects that were using our base project would be updated (best is through Composer with composer update).
For example, Kartik has its plugins/widgets and we can simply update through Composer with command like $ php composer.phar require kartik-v/yii2-grid "#dev".
So we want to have something similar, but not accessible publicly (so that random people couldn't access without some sort of email/username/password). This part is not as important as the first part because in this part we at least can use something like BitBucket. There aren't many possible solutions, most likely a few only, actually, but it's a challenge that we cannot solve right now.
I have tried StackExchange but it's not as popular StackOverflow, so I'm trying to give as much information as I can. Assuming I see this question, this question shouldn't be off-topic either. Thanks!
You could use your own private repository for keeping yii2 app template. To update all your projects use composer. Here's code example:
"repositories": [
{
"type":"package",
"package": {
"name": "repo-name/yii2template",
"version":"master",
"source": {
"url": "https://your-git-server.com/repo-name/yii2template.git",
"type": "git",
"reference":"master"
}
}
}
],
So when you make changes to your template, you just update composer for certain project and get those changes.
P.S. Another idea is Ansible. You can update child projects by this tool, but you have to write playbook manually for your needs.
If you need this template local only, you could use PhpStorm, it can make templates from project.
I am trying to integrate Agile CRM in my Symfony2 application.
There is a PHP library provided by Agile :
https://github.com/agilecrm/php-api
However it's not a bundle.
How can I integrate it correctly in my application? Should I put a require once in my app.php or my kernel? Or is there a better way?
Composer has a feature to auto load files
https://getcomposer.org/doc/04-schema.md#files
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
Other ways ?
Expose the functionality as a Service using the code provided in the library.
I think the best way to do this is to:
contribute to the project to add a composer.json
contribute to allow the configuration to be loaded from elsewhere instead of being hardcoded
Then you'll be abled to simply use composer to load that package. :)
Composer (as mentioned in other answers) is only a dependency manager and therefore only part of the solution. If you are really interested in the cleanest way, it is quite simple: write the bundle yourself.
In fact, there are many examples of bundles that work as integration layers for 3rd party libraries. For example, look at https://github.com/nelmio/alice, a Symfony2 bundle meant to wrap Faker, an external data fixture lib.
A bundle may declare configuration options overridable by the app main config files. It may expose service definitions for the library objects so that you can avoid to create them manually and inject them when needed (whether or not the library is written with DI in mind). It may be also useful for twig extensions, event listeners and so on.
A good written bundle promotes reuse, testability and separation of concern. Don't be scared from writing your bundle from scratch, start here http://symfony.com/doc/current/cookbook/bundles/best_practices.html
As agilecrm/php-api is not available on Packagist the best approach would be to add the repository to your composer.json file and then install the package the same way you would with everything else.
{
//...
"repositories": [
{
"type": "package",
"package": {
"name": "agilecrm/php-api",
"version": "2.1.0",
"source": {
"url": "https://github.com/agilecrm/php-api",
"type": "git",
"reference": "2.1.0"
}
}
}
],
"require": {
//...
"agilecrm/php-api": "2.1.0"
}
//...
}
You should add it to your composer.json
{
"require": {
"agilecrm/php-api": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#github.com:agilecrm/php-api.git"
}
]
}
or you can add it to composer autoloader https://getcomposer.org/doc/01-basic-usage.md#autoloading
I am working on several projects but each one connects to a REST web service.
I've developed the first one using Laravel, and developed a few classes really useful to communicate with the web services.
I would like to start the second one, and of course, reuse the classes developed for the REST connection.
My problem is, my company wants me to use several git directories for the projects, and each one should be uploaded to a different springloops project.
Springloops is a bit like github, you can upload your code using git.
How would you proceed to avoid copy/paste and use the same laravel code but in different projects (and I guess, in different locations)?
I'm not sure I'm really clear, but don't hesitate to ask me for more information if you need to.
Thanks.
How about creating your own Composer package and store it in a separate (private) Git repo? As far as Composer is concerned it's just like any other package, you may want to check out this section of the docs:
Using private repositories
Exactly the same solution allows you to work with your private
repositories at GitHub and BitBucket:
{
"require": {
"vendor/my-private-repo": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo.git"
}
]
}
The only requirement is the installation of SSH keys for a git client.
I've developed my own PHP framework which is used to power many different apps. At the moment, it uses Twig, Symfony YAML, Monolog and Facebook SDK as components. Now I need to create an admin section so those who update the content can login to a secure area, and very likely a user section, so their would be different roles too.
I like the look of Zend and Symfony's components and I have found many Stack Overflow questions related to it, but I was wondering:
If I use Symfony2's Security Component, how do I use it outside of the Symfony2 framework? This is very frustratingly missing from the Components Handbook, seeing as they've documented every other of their components.
If I use Zend_Auth and Zend_Acl, can I load them with Composer, without downloading the full stack? Or would I have to download it manually and extract the classes?
Do you recommend another package?
Found the solution. http://packages.zendframework.com/
Reason I didn't find this out earlier, Zend 2 uses it's own repository instead of Packagist.
Composer.json:
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
and
"require": {
"zendframework/zend-authentication": "2.0.*",
"zendframework/zend-permissions-acl": "2.0.*"
},
"minimum-stability": "beta"
Though I'm using "minimum-stability": "dev" for my project