Symfony2 and Google API integration - google-api

I am going to use Google API located on http://google-api-php-client.googlecode.com/svn/trunk/ with my Symfony2 application.
Is it possible to import this API with composer ?
What is the best practice to use this API with my application ?

It's probably too late, but there is no need to use forked git repos, you can refer to Google's "native" svn directly.
Add the following section to your composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "project/google-api-php-client",
"version": "1.0.0",
"source": {
"type": "svn",
"url": "http://google-api-php-client.googlecode.com/svn",
"reference": "trunk"
}
}
}
]
Notes:
"project/google-api-php-client" name there can be any of your choice
If you need a particular revision, use "trunk#revision-number-here" format in "reference" entry
Then add the following line to your "require" section:
"require": {
...
"project/google-api-php-client": "1.0.0"
}
That'll make composer to checkout the repo on the next update/install.
If you want Google API classes to be autoloaded, add the following line to your "autoload" section:
"autoload": {
...
"classmap": ["vendor/project/google-api-php-client/src"]
}
It doesn't seem very neat to put the full path into the global "autoload" section, but I didn't manage to make it work with "autoload" section under `repository/package" yet :(

Google have now started using github and have added a composer.json file.
Github: https://github.com/google/google-api-php-client
Packagist: https://packagist.org/packages/google/apiclient
"require": {
...
"google/apiclient": "dev-master"
}
It's a shame there is no namespaces, but they are closer than before by having a composer file.

There is a Symfony2 bundle wrapping the official Google API library published by Google on Github in 2014. That way, the API client is available as a service and you can store your configuration in the Symfony2 config file.
Symfony2 Bundle: https://github.com/Happyr/GoogleApiBundle
$ composer require happyr/google-api-bundle
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new HappyR\Google\ApiBundle\HappyRGoogleApiBundle(),
);
}

There github repository for Google API https://github.com/evert/google-api-php-client with composer.
You can add to your composer.json file: "evert/google-api-php-client"

Related

How to deploy to GitHub pages with Web Components Dependencies in Node Modules

I am trying to host my web site using Github Pages. I am currently using Web Components and Lit-HTML (No Lit Element). No server side code. Just using NPM and Node Modules. I am wanting to build the site and publish to my git branch gh-pages but I am not quite sure what steps I need to take as currently the page error as it can not find the dependencies.
I am currently running the site locally using WAMP on my Windows Machine. Works perfectly here. Not sure if its possible to compile the code so that its in a Jekyll format
EDIT: I know how to push the code to Github. Just not sure how Github uses Node Modules to build the site.
Here is my Package.json
{
"name": "Repo",
"version": "1.0.0",
"description": "Description",
"dependencies": {
"#webcomponents/webcomponentsjs": "^2.2.1",
"lit-html": "^1.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/username/Repo.git"
},
"author": "ME",
"license": "ISC",
"bugs": {
"url": "https://github.com/username/Repo/issues"
},
"homepage": "https://homepage.com"
}
It depends from where you want to get the dependencies.
Do you want to host them yourself on your own site? Maybe it's not necessary. Instead you could get them directly from their original CDN.
For webcomponentsjs, according to their website, it's on the unpkg.com CDN.
<script src="https://unpkg.com/#webcomponents/webcomponentsjs#^2/webcomponents-bundle.js"></script>
For lit-html, according to the doc, it's on the unpkg.com CDN too:
import {html, render} from 'https://unpkg.com/lit-html?module'

Project Structure with composer

I'm trying to create a project with composer-file.
Reason is primarily a dependency which I never want to upload to git.
My intended structure is this:
project-root-folder
- project-sub-folder(s)
- vendor (with required dependencies)
- index.php
- composer.json
- README.md
But the installed structure using composer is this:
project-root-folder
- vendor
- vendor/composer
- vendor/smarty (dependency)
- vendor/my-project
- composer.json
I know that there are special installers for many different projects, I just don't understand that an installer is required to get the intended structure and also not how to do it without a special installer.
This is the content of one composer file I tried:
{
"name": "wdb/tutorial-oop",
"require": {
"smarty/smarty": "~3.1"
}
}
When I tried this composer-json content in a local file and just extecute composer install I get the same structure:
{
"require": {
"wdb/tutorial-oop": "dev-master"
}
}
So my question is, how a composer file has to look that the project structure is created like I described in the top of this question. The basic problem is that I don't want my project being installed as dependency in the vendor-directory but in the root of the project folder, and additionally that I don't want to use the composer autoloader.
Edit:
On request here my full composer file inside the project root:
{
"name": "wdb/tutorial-oop",
"type": "project",
"description": "Your package description goes here",
"keywords": ["oop","mvc","tutorial"],
"homepage": "https://barlians.com",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "David Bruchmann",
"email": "david.bruchmann#gmail.com",
"homepage": "https://barlians.com",
"role": "Author, Developer"
}
],
"support": {
"email": "david.bruchmann#gmail.com"
},
"require": {
"smarty/smarty": "~3.1"
}
}
You're installing your project in incorrect way. The composer require command is for installing dependencies, so they're installed to the vendor directory.
For installing a project you should use the create-project command:
composer create-project wdb/tutorial-oop

Why I can't use composer require {packageName} successfully?

I'm learn how to create Laravel packages, And I wrote a package here: noahprot/fillindata
Then I submit it to packagist
And I have set a lastest release in github
And the Packagist show like this:
Already show the latest release
Then I use Laravel CLI Tool create a new laravel project, I want try to use this package, and I use composer require noahprot/fillindata
But the result like this:
[InvalidArgumentException]
Could not find a version of package noahprot/fillindata matching your
minimum-stability (dev). Require it with an explicit version con
straint allowing its desired stability.
my package's composer.json file like this:
{
"name": "noahprot/fillindata",
"License": "MIT",
"description": "take the csv file fill into database table",
"authors": [
{
"name": "Noah Prot",
"email": "mylovewangjian#gmail.com"
}
],
"autoload": {
"psr-4": {
"NeoLee\\Fillindata\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"NoahProt\\Fillindata\\FillindataServiceProvider"
]
}
},
"require": {}
}
I make some try like:
add "minimum-stability": "dev" to composer.json, but failed,
even I edit to "stable", but failed too;
I have no idea for this situation now;
Guys, Please Help me, and give some advice, please!
Thank you everyone!
It seems that Packagist have some cache-related problems, see this issue. Mirror you're using probably have some outdated packages info. At this point you can do only two things:
Wait until packages data on mirror will be refreshed.
Report your case (see this comment).

Composer only finds latest version (tag) of Gitlab hosted package

I have created a package with some annotated tags for versioning (1.0.0, 1.0.1, 1.1.0 and 2.0.0). This package lives on own hosting (so not via Packagist)
When trying to require the package, composer only finds the 2.0.0 version and fails on any other version requirement.
Composer.php file of project using package
{
"name": "projectname",
"description": "Description.",
"keywords": ["keys"],
"license": "Licence",
"type": "project",
"require": {
...
"space/package-name": "~1.0" // Also tried 1.0.0, 1.0.*, ~1.0#dev - only 2.0.0 works
}
"repositories": [
...
{
"type": "git",
"url": "git#gitlab.com:space/package-name.git" // Make sure package is found on specific hosting
}
],
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
On running composer show "space/package-name" I get versions: * 2.0.0. So upon update, composer produces the following error:
The requested package space/package-name ~1.0 exists as name/package-
name[2.0.0, dev-master] but these are rejected by your constraint.
It looks like composer is no able to find any other version than the latest, any way of fixing this?
Things already checked:
The package does not contain a version in the composer.json (that might conflict with the git tag)
Used tags are annotated tags and are pushed to the repo.
Updates:
Might be a Gitlab - Composer issue, see this comment.
Gitlab doesn't always provide tag info when Composer tries to read the repo.
Solution: also add version info in composer.json:
{
"name": "package/name",
"version": "1.0.0",
...
}
This will be readable by composer. Careful: Git tags must match versioning info in composer.json! (might cause errors otherwise)

packagist / composer - Assign a version number

I have people using my pacakgist library.
I want to make sure that their composer.json version requirement stated as "dev-master" will not get updated when they run composer update... as I have changed the underlying architecture of the package.
How do I assign a new versioning to my new update? so that they have to explicitly say I want v1.01
I currently have the composer.json as:
{
"name": ...,
"type": "library",
"description": ...,
"keywords": ...
"homepage": ...,
"license": "MIT",
"authors": [
...
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"classmap": ["Models/"]
}
}
The composer documentation recommends specifying the version using a VCS tag. With git this looks like
git tag -a 1.0.0 -m 'Your tag message'
This will tag the HEAD of your current branch with the version 1.0.0. Then do
git push --tags
Once your package gets crawled again, the version should be available on packagist.

Resources