<?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 &#8220;blog/tutorial&#8221; as a package name. I prefer to use bitbucket and at the below code [&#8230;]</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 &#8220;blog/tutorial&#8221; 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 &#8220;composer.json&#8221;  , 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": "&gt;=5.4",
    },
    "require-dev": {
        "phpunit/phpunit": "~4.6"
    },
    "autoload": {
        "psr-4": {
            "Mtigdemir\\Blog\\": "src/"
        }
    }
}</pre>
<p>As you can see, I&#8217;ve defined autoload psr-4 property with namespace &#8220;Mtigdemir\\Blog\\&#8221;</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 ">&lt;?php namespace Mtigdemir\Blog;
// File must be under src directory
class User
{
	private $username; 
	private $email; 

	public function __constructor($username , $email){
		$this-&gt;username = $username;
		$this-&gt;email = $email;
	}

	public function getEmail(){
		return $this-&gt;email;
	}

	public function getUsername(){
		return $this-&gt;username;
	}
}</pre>
<p>Let&#8217;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&#8217;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 &#8220;git@bitbucket.org:mtigdemir/blog-tutorial.git&#8221; 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": "&gt;=5.4",
    }
  }
</pre>
<pre class="lang:default decode:true">composer search mtigdemir</pre>
<p>This composer command will find &#8220;mtigdemir&#8221; 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> &#8220;mtigdemir/blog-tutorial Blog tutorial Package&#8221;</em></strong></p>
<pre class="lang:default decode:true">composer info mtigdemir/blog-tutorial</pre>
<p>What about version ! I didn&#8217;t release any version , in that case if you pushed develop or master branch your requirement version will change that&#8217;s why composer info is very useful. My package version is &#8220;dev-master&#8221;</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\ =&gt; src/

requires
php &gt;=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&#8217;m able to use my class in project &#8212; 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">&lt;?php
	
require "vendor/autoload.php";

$user = new \Mtigdemir\Blog\User("muharrem" , "muharrem.tigdemir@gmail.com");

echo $user-&gt;getUserName().'__'.$user-&gt;getEmail();
</pre>
<p>I&#8217;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>