<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" > <channel> <title>Version Control | Muharrem Tığdemir</title> <atom:link href="/category/version-control/feed/" rel="self" type="application/rss+xml" /> <link></link> <description>Carpe Diem!!</description> <lastBuildDate>Fri, 21 Aug 2015 06:43:16 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod> hourly </sy:updatePeriod> <sy:updateFrequency> 1 </sy:updateFrequency> <generator>https://wordpress.org/?v=6.2.2</generator> <site xmlns="com-wordpress:feed-additions:1">120145533</site> <item> <title>Bitbucket Repository with Composer</title> <link>/bitbucket-repository-with-composer/</link> <comments>/bitbucket-repository-with-composer/#respond</comments> <dc:creator><![CDATA[Muharrem Tığdemir]]></dc:creator> <pubDate>Fri, 21 Aug 2015 06:43:16 +0000</pubDate> <category><![CDATA[PHP]]></category> <category><![CDATA[Version Control]]></category> <category><![CDATA[bitbucket]]></category> <category><![CDATA[composer]]></category> <category><![CDATA[git]]></category> <guid isPermaLink="false">https://muharremtigdemir.com/?p=616</guid> <description><![CDATA[<p>Hi all, In this article , you will find a tutorial about , how to use github or bitbucket repositories with composer. Create Your Repository Most important thing in this step, we will use the repository name in composer.json. I used “blog/tutorial” as a package name. I prefer to use bitbucket and at the below code […]</p> <p>The post <a href="/bitbucket-repository-with-composer/">Bitbucket Repository with Composer</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></description> <content:encoded><![CDATA[<p>Hi all,</p> <p>In this article , you will find a tutorial about , <strong><span style="text-decoration: underline;">how to use github or bitbucket repositories with composer</span></strong>.</p> <h3>Create Your Repository</h3> <p>Most important thing in this step, we will use the repository name in composer.json. I used “blog/tutorial” as a package name. I prefer to use bitbucket and at the below code copied from bitbucket repository page, following commands will init git repository to your local folder.</p> <pre class="lang:default decode:true">mkdir /path/to/your/project cd /path/to/your/project git init git remote add origin git@bitbucket.org:yourname/blog-tutorial.git</pre> <h3>Create Composer.json</h3> <p>Now, i defined a composer properties like , package name , description , authors , requirements etc.. For more information about composer.json please check <a href="https://getcomposer.org/doc/01-basic-usage.md#package-names">Composer Basic Usage</a></p> <p><strong>Note:</strong> When you finished to edit “composer.json” , dont forget to run</p> <pre class="lang:default decode:true">composer validate</pre> <pre class="lang:default decode:true">{ "name": "mtigdemir/blog-tutorial", "description": "Muharrem Tigdemir Blog Tutorial Package", "authors": [ { "name": "Muharrem Tığdemir", "email": "muharrem.tigdemir@gmail.com" } ], "require": { "php": ">=5.4", }, "require-dev": { "phpunit/phpunit": "~4.6" }, "autoload": { "psr-4": { "Mtigdemir\\Blog\\": "src/" } } }</pre> <p>As you can see, I’ve defined autoload psr-4 property with namespace “Mtigdemir\\Blog\\”</p> <p><span style="text-decoration: underline;"><strong>!IMPORTANT!</strong></span> <a href="http://www.php-fig.org/psr/psr-0/">PSR-0 is deprecated</a> , and PSR-4 standarts show us where to place files that will be autoloaded according to the specification. For more information about PSR-4 please check <a href="http://www.php-fig.org/psr/psr-4/">PHP Framework Interop Group</a></p> <pre class="lang:php mark:3 decode:true " title="User.php Class with namespace "><?php namespace Mtigdemir\Blog; // File must be under src directory class User { private $username; private $email; public function __constructor($username , $email){ $this->username = $username; $this->email = $email; } public function getEmail(){ return $this->email; } public function getUsername(){ return $this->username; } }</pre> <p>Let’s create a <em>User.class in src/</em> directory with <span style="text-decoration: underline;"><strong>Mtigdemir\Blog</strong></span> namespace. Your package is ready to use with User class lets push it !</p> <h3>It’s time to include our package into the project</h3> <p>First of all, we have to include our repository to new project at the below composer.json definition is my new project and I included “git@bitbucket.org:mtigdemir/blog-tutorial.git” to my repositories.</p> <p><strong><em>Note : if you are using private repository. You have add your ssh-key to bitbucket!</em></strong></p> <pre class="lang:default decode:true" title="Project composer.json">{ "name" : "mtigdemir/blog-tutorial-project", "description" : "Blog Tutorial Project", "repositories": [ { "type": "vcs", "url": "git@bitbucket.org:mtigdemir/blog-tutorial.git" } ], "require": { "php": ">=5.4", } } </pre> <pre class="lang:default decode:true">composer search mtigdemir</pre> <p>This composer command will find “mtigdemir” packages including my private repository , as a result composer will find our package name and description if everything is cool you will see this kind of result in command line about your package definition:<strong><em> “mtigdemir/blog-tutorial Blog tutorial Package”</em></strong></p> <pre class="lang:default decode:true">composer info mtigdemir/blog-tutorial</pre> <p>What about version ! I didn’t release any version , in that case if you pushed develop or master branch your requirement version will change that’s why composer info is very useful. My package version is “dev-master”</p> <pre class="lang:default decode:true" title="My Package information">name : mtigdemir/blog-tutorial descrip. : Blog tutorial Package keywords : versions : dev-master type : library source : [git] git@bitbucket.org:mtigdemir/blog-tutorial.git f37affd9a2f1500a4ff956aa727304ce66af951b dist : [] names : mtigdemir/blog-tutorial autoload psr-4 Bumin\Psp\Account\ => src/ requires php >=5.4 requires (dev) phpunit/phpunit ~4.6 </pre> <p>Now , you can add your package like at the below or add package to composer.json and update it !</p> <pre class="lang:default decode:true">composer require mtigdemir/blog-tutorial:dev-master</pre> <h3>Finally, I’m able to use my class in project — Yea only User Class user.php :((</h3> <p>Your package will be under <strong><em>vendor/</em></strong> directory like other packages from packagist.org.</p> <pre class="lang:default decode:true"><?php require "vendor/autoload.php"; $user = new \Mtigdemir\Blog\User("muharrem" , "muharrem.tigdemir@gmail.com"); echo $user->getUserName().'__'.$user->getEmail(); </pre> <p>I’m able to use my User Class with namespace ,</p> <p>I want to thank to my team-mate Aykut Aras for share with me all about this know-how..</p> <p>Muharrem Tığdemir</p><p>The post <a href="/bitbucket-repository-with-composer/">Bitbucket Repository with Composer</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></content:encoded> <wfw:commentRss>/bitbucket-repository-with-composer/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <post-id xmlns="com-wordpress:feed-additions:1">616</post-id> </item> </channel> </rss>