Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Update Composer install section in README.md #788

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 51 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Microsoft Azure tables, blobs, queues, service bus (queues and topics), service
* deployment: create, get, delete, swap, change configuration, update status, upgrade, rollback
* role instance: reboot, reimage
* REST API Version: 2011-10-01
* Media Services
* Media Services
* Connection
* Ingest asset, upload files
* Encoding / process asset, create job, job templates
Expand All @@ -47,7 +47,7 @@ Microsoft Azure tables, blobs, queues, service bus (queues and topics), service
* Scale encoding reserved unit type
* REST API Version: 2.11


# Getting Started
## Download Source Code

Expand All @@ -57,26 +57,33 @@ To get the source code from GitHub, type
cd ./azure-sdk-for-php

> **Note**
>
>
> The PHP Client Libraries for Microsoft Azure have a dependency on the [HTTP_Request2](http://pear.php.net/package/HTTP_Request2), [Mail_mime](http://pear.php.net/package/Mail_mime), and [Mail_mimeDecode](http://pear.php.net/package/Mail_mimeDecode) PEAR packages. The recommended way to resolve these dependencies is to install them using the [Composer package manager](http://getcomposer.org).


##Install via Composer
1. Make sure you have installed **[Compoeser](https://getcomposer.org/doc/00-intro.md#introduction)** in your system.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the "Add requirement and install with one command" section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this operation applies for both cases. This library shouldn't be responsible to provide instructions on how install 3rd party tools. Take into account that the installation process can change in any moment, so it is better to point the users to the original source. Indeed, the recommended install process for Composer has been updated a short time ago.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the install process for Composer can change, and I don't want new users to be distracted by that, I want them just "Download composer.phar in your project root" and it will work. No need to configure it locally or globally. It will always work. Your instruction "php composer install " will only work when configured globally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, taking your concern into account I'll update all the references based on composer.phar being available at project's root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the new install process states the following commands in order to ensure package consistency, security and system settings:

php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === '7228c001f88bee97506740ef0888240bd8a760b046ee16db8f4095c0d8d525f2367663f22a46b48d072c816e7fe19959') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

With your request, all of these checks and features will be lost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is checking the integrity of the installer. if the users downloads composer.phar, they don't have this risk at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines obviously are checking the integrity of the installer, but the installer itself has a lot of other checks. You can take a look at the composer repo.
Whatever, downloading a file directly from a remote server without any check of integrity (like you are proposing) is very vulnerable for any kind of attack, like MITM by instance.
You can dive into this topic at this issue and take it just as an example.

It can be installed locally or globally depending on your own needs.

2. You can edit your `composer.json` file manually or directly add the requirement via CLI:

* Create a file named **composer.json** in the root of your project and add the following code to it:
###Manually edit
Create or edit your **composer.json** in the root of your project and add the following code to it:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this section, I would just use the original text, so new users will not be distracted by composer operations.

```json
{
"require": {
"microsoft/windowsazure": "^0.4"
}
{
"require": {
"microsoft/windowsazure": "^0.4"
}
}
```

* Download **[composer.phar](http://getcomposer.org/composer.phar)** in your project root.

* Open a command prompt and execute this in your project root

php composer.phar install
php composer install

###Add requirement and install with one command
Execute the following command in order to get this package:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you have included all necessary config steps for composer to work here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only command required @yaqiyang, you think I missed something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It can be installed** locally or globally **depending on your own needs. ". But you told me you have to install it globally for your command to work. I know it does not work on my machine since I have not got a chance to install composer yet. I only have composer.phar downloaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said @yaqiyang, I have installed globally, and I renamed composer.phar to just composer. It only is one of the proposed practices described at the Composer documentation. Please take into account that it is a PHAR file, so the only difference in my case is that I have it placed (moved) in a path which is part of my environment variables. There is no other process that take place at the tool install.

php composer create-project microsoft/windowsazure /path/to/install/dir ^0.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to have .phar here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try your command? php composer.phar create-project microsoft/windowsazure ./test2 ^0.4 will try to install v0.4.0, not v0.4.2.

php composer.phar create-project microsoft/windowsazure ./test3 ^0.4.2 does not work either

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are so many hoops to jump, this will not work for beginners which is the Readme file for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaqiyang, I'll try to address your comments one by one:

  • as I have composer installed globally and my executable is called composer, I don't need to suffix the call with .phar:
$ which composer
/usr/local/bin/composer

Obviously, it depends on which mechanism the user chooses based on the install documentation: https://getcomposer.org/doc/00-intro.md

  • I have no issues installing 0.4.2 version with this command:
$ composer create-project microsoft/windowsazure testing-resolved-version ^0.4
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Installing microsoft/windowsazure (v0.4.2)
  - Installing microsoft/windowsazure (v0.4.2)
    Loading from cache

Created project in testing-resolved-version
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing firebase/php-jwt (v3.0.0)
    Loading from cache

  - Installing pear/pear_exception (v1.0.0)
    Loading from cache

  - Installing pear/net_url2 (v2.2.0)
    Loading from cache

  - Installing pear/http_request2 (v2.3.0)
    Loading from cache

  - Installing pear/console_getopt (v1.4.1)
    Loading from cache

  - Installing pear/pear-core-minimal (v1.10.1)
    Loading from cache

  - Installing pear/mail_mime (1.10.0)
    Loading from cache

  - Installing pear/mail_mime-decode (1.5.5.2)
    Loading from cache

  - Installing mikey179/vfsstream (v1.6.2)
    Loading from cache

  - Installing phpdocumentor/reflection-docblock (2.0.4)
    Downloading: 100%         

  - Installing phpunit/php-token-stream (1.4.8)
    Downloading: 100%         

  - Installing symfony/yaml (v3.0.4)
    Loading from cache

  - Installing sebastian/version (1.0.6)
    Loading from cache

  - Installing sebastian/global-state (1.1.1)
    Downloading: 100%         

  - Installing sebastian/recursion-context (1.0.2)
    Downloading: 100%         

  - Installing sebastian/exporter (1.2.1)
    Downloading: 100%         

  - Installing sebastian/environment (1.3.5)
    Loading from cache

  - Installing sebastian/diff (1.4.1)
    Downloading: 100%         

  - Installing sebastian/comparator (1.2.0)
    Downloading: 100%         

  - Installing phpunit/php-text-template (1.2.1)
    Downloading: 100%         

  - Installing doctrine/instantiator (1.0.5)
    Downloading: 100%         

  - Installing phpunit/phpunit-mock-objects (2.3.8)
    Loading from cache

  - Installing phpunit/php-timer (1.0.7)
    Downloading: 100%         

  - Installing phpunit/php-file-iterator (1.4.1)
    Downloading: 100%         

  - Installing phpunit/php-code-coverage (2.2.4)
    Loading from cache

  - Installing phpspec/prophecy (v1.6.0)
    Loading from cache

  - Installing phpunit/phpunit (4.8.24)
    Loading from cache

phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Generating autoload files
  • I don't understand your point, what you mean with "so many hoops"? I don't share your conception about the README file, since I think it isn't only for beginners but a documentation piece that must cover the main concepts of the project which is described within it.


> **Note**
>
Expand All @@ -86,12 +93,12 @@ To get the source code from GitHub, type

## Getting Started

There are four basic steps that have to be performed before you can make a call to any Microsoft Azure API when using the libraries.
There are four basic steps that have to be performed before you can make a call to any Microsoft Azure API when using the libraries.

* First, include the autoloader script:

require_once "vendor/autoload.php";
require_once "vendor/autoload.php";

* Include the namespaces you are going to use.

To create any Microsoft Azure service client you need to use the **ServicesBuilder** class:
Expand All @@ -102,15 +109,15 @@ There are four basic steps that have to be performed before you can make a call

use WindowsAzure\Common\ServiceException;

* To instantiate the service client you will also need a valid connection string. The format is:

* To instantiate the service client you will also need a valid connection string. The format is:

* For accessing a live storage service (tables, blobs, queues):

DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]

* For accessing the emulator storage:

UseDevelopmentStorage=true

* For accessing the Service Bus:
Expand Down Expand Up @@ -221,9 +228,9 @@ The following are examples of common operations performed with the Blob serivce.
```PHP
// OPTIONAL: Set public access policy and metadata.
// Create container options object.
$createContainerOptions = new CreateContainerOptions();
$createContainerOptions = new CreateContainerOptions();

// Set public access policy. Possible values are
// Set public access policy. Possible values are
// PublicAccessType::CONTAINER_AND_BLOBS and PublicAccessType::BLOBS_ONLY.
// CONTAINER_AND_BLOBS: full public read access for container and blob data.
// BLOBS_ONLY: public read access for blobs. Container data not available.
Expand Down Expand Up @@ -277,7 +284,7 @@ try {
// List blobs.
$blob_list = $blobRestProxy->listBlobs("mycontainer");
$blobs = $blob_list->getBlobs();

foreach($blobs as $blob)
{
echo $blob->getName().": ".$blob->getUrl()."<br />";
Expand Down Expand Up @@ -317,7 +324,7 @@ try {
```

[Error Codes and Messages for Queues](http://msdn.microsoft.com/en-us/library/windowsazure/dd179446.aspx)


### Add a message to a queue

Expand Down Expand Up @@ -398,20 +405,20 @@ try {
```

## Service Bus Queues
The current PHP Service Bus APIs only support ACS connection strings. You need to use PowerShell to create a new ACS Service Bus namespace at the present time.
First, make sure you have Azure PowerShell installed, then in a PowerShell command prompt, run
The current PHP Service Bus APIs only support ACS connection strings. You need to use PowerShell to create a new ACS Service Bus namespace at the present time.
First, make sure you have Azure PowerShell installed, then in a PowerShell command prompt, run
```
Add-AzureAccount # this will sign you in
New-AzureSBNamespace -CreateACSNamespace $true -Name 'mytestbusname' -Location 'West US' -NamespaceType 'Messaging'
```
If it is sucessful, you will get the connection string in the PowerShell output. If you get connection errors with it and the conection string looks like Endpoint=sb://..., change it to **Endpoint=https://...**

### Create a Queue

```PHP
try {
$queueInfo = new QueueInfo("myqueue");

// Create queue.
$serviceBusRestProxy->createQueue($queueInfo);
} catch(ServiceException $e){
Expand Down Expand Up @@ -454,14 +461,14 @@ try {
// Set the receive mode to PeekLock (default is ReceiveAndDelete).
$options = new ReceiveMessageOptions();
$options->setPeekLock(true);

// Receive message.
$message = $serviceBusRestProxy->receiveQueueMessage("myqueue", $options);
echo "Body: ".$message->getBody()."<br />";
echo "MessageID: ".$message->getMessageId()."<br />";

// *** Process message here ***

// Delete message.
$serviceBusRestProxy->deleteMessage($message);
} catch(ServiceException $e){
Expand All @@ -476,7 +483,7 @@ try {
### Create a Topic

```PHP
try {
try {
// Create topic.
$topicInfo = new TopicInfo("mytopic");
$serviceBusRestProxy->createTopic($topicInfo);
Expand Down Expand Up @@ -524,7 +531,7 @@ try {

The primary way to receive messages from a subscription is to use a **ServiceBusRestProxy->receiveSubscriptionMessage** method. Received messages can work in two different modes: **ReceiveAndDelete** (the default) and **PeekLock** similarly to Service Bus Queues.

The example below demonstrates how a message can be received and processed using **ReceiveAndDelete** mode (the default mode).
The example below demonstrates how a message can be received and processed using **ReceiveAndDelete** mode (the default mode).

```PHP
try {
Expand All @@ -533,8 +540,8 @@ try {
$options->setReceiveAndDelete();

// Get message.
$message = $serviceBusRestProxy->receiveSubscriptionMessage("mytopic",
"mysubscription",
$message = $serviceBusRestProxy->receiveSubscriptionMessage("mytopic",
"mysubscription",
$options);
echo "Body: ".$message->getBody()."<br />";
echo "MessageID: ".$message->getMessageId()."<br />";
Expand All @@ -549,17 +556,17 @@ try {

### Set-up certificates

You need to create two certificates, one for the server (a .cer file) and one for the client (a .pem file). To create the .pem file using [OpenSSL](http://www.openssl.org), execute this:
You need to create two certificates, one for the server (a .cer file) and one for the client (a .pem file). To create the .pem file using [OpenSSL](http://www.openssl.org), execute this:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

To create the .cer certificate, execute this:
To create the .cer certificate, execute this:

openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer

### List Available Locations

```PHP
```PHP
$serviceManagementRestProxy->listLocations();
$locations = $result->getLocations();
foreach($locations as $location){
Expand All @@ -579,11 +586,11 @@ $options->setLocation('West US');

$result = $serviceManagementRestProxy->createStorageService($name, $label, $options);
```


### Create a Cloud Service

A cloud service is also known as a hosted service (from earlier versions of Microsoft Azure). The **createHostedServices** method allows you to create a new hosted service by providing a hosted service name (which must be unique in Microsoft Azure), a label (the base 64-endcoded hosted service name), and a **CreateServiceOptions** object which allows you to set the location *or* the affinity group for your service.
A cloud service is also known as a hosted service (from earlier versions of Microsoft Azure). The **createHostedServices** method allows you to create a new hosted service by providing a hosted service name (which must be unique in Microsoft Azure), a label (the base 64-endcoded hosted service name), and a **CreateServiceOptions** object which allows you to set the location *or* the affinity group for your service.

```PHP
$name = "myhostedservice";
Expand Down Expand Up @@ -684,11 +691,11 @@ $streamingUrl = $originLocator->getPath() . '[Manifest file name]' . "/manifest"

###Manage media services entities

Media services CRUD operations are performed through media services rest proxy class. It has methods like “createAsset”, “createLocator”, “createJob” and etc. for entities creations.
Media services CRUD operations are performed through media services rest proxy class. It has methods like “createAsset”, “createLocator”, “createJob” and etc. for entities creations.

To retrieve all entities list you may use methods “getAssetList”, “getAccessPolicyList”, “getLocatorList”, “getJobList” and etc. For getting single entity data use methods “getAsset”, “getJob”, “getTask” and etc. passing the entity identifier or entity data model object with non-empty identifier as a parameter.
To retrieve all entities list you may use methods “getAssetList”, “getAccessPolicyList”, “getLocatorList”, “getJobList” and etc. For getting single entity data use methods “getAsset”, “getJob”, “getTask” and etc. passing the entity identifier or entity data model object with non-empty identifier as a parameter.

Update entities with methods like “updateLocator”, “updateAsset”, “updateAssetFile” and etc. passing the entity data model object as a parameter. It is important to have valid entity identifier specified in data model object.
Update entities with methods like “updateLocator”, “updateAsset”, “updateAssetFile” and etc. passing the entity data model object as a parameter. It is important to have valid entity identifier specified in data model object.

Erase entities with methods like “deleteAsset”, “deleteAccessPolicy”, “deleteJob” and etc. passing the entity identifier or entity data model object with non-empty identifier as a parameter.

Expand Down