mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-10 15:54:01 +02:00
Made the following changes: Removed class, standardised property names to camel case and switched method names.
This commit is contained in:
@@ -165,27 +165,27 @@ interface OutputInterface
|
|||||||
public function load();
|
public function load();
|
||||||
}
|
}
|
||||||
|
|
||||||
class OutputSerializedArray implements OutputInterface
|
class SerializedArrayOutput implements OutputInterface
|
||||||
{
|
{
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
return serialize($array_of_data);
|
return serialize($arrayOfData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OutputJsonString implements OutputInterface
|
class JsonStringOutput implements OutputInterface
|
||||||
{
|
{
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
return json_encode($array_of_data);
|
return json_encode($arrayOfData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OutputArray implements OutputInterface
|
class ArrayOutput implements OutputInterface
|
||||||
{
|
{
|
||||||
public function load()
|
public function load()
|
||||||
{
|
{
|
||||||
return $array_of_data;
|
return $arrayOfData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
@@ -203,15 +203,13 @@ behaviour required at runtime:
|
|||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SomeClientClass
|
class SomeClient
|
||||||
{
|
{
|
||||||
private $output;
|
private $output;
|
||||||
|
|
||||||
public function __construct(){}
|
public function setOutput(OutputInterface $outputType)
|
||||||
|
|
||||||
public function setOutput(OutputInterface $output_type)
|
|
||||||
{
|
{
|
||||||
$this->output = $output_type;
|
$this->output = $outputType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadOutput()
|
public function loadOutput()
|
||||||
@@ -227,14 +225,14 @@ that has been set.
|
|||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$client = new SomeClientClass();
|
$client = new SomeClient();
|
||||||
|
|
||||||
// Want an array?
|
// Want an array?
|
||||||
$client->setOutput(new OutputArray());
|
$client->setOutput(new ArrayOutput());
|
||||||
$data = $client->loadOutput();
|
$data = $client->loadOutput();
|
||||||
|
|
||||||
// Want some JSON?
|
// Want some JSON?
|
||||||
$client->setOutput(new OutputJsonString());
|
$client->setOutput(new JsonStringOutput());
|
||||||
$data = $client->loadOutput();
|
$data = $client->loadOutput();
|
||||||
|
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
Reference in New Issue
Block a user