mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-09 07:26:29 +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();
|
||||
}
|
||||
|
||||
class OutputSerializedArray implements OutputInterface
|
||||
class SerializedArrayOutput implements OutputInterface
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return serialize($array_of_data);
|
||||
return serialize($arrayOfData);
|
||||
}
|
||||
}
|
||||
|
||||
class OutputJsonString implements OutputInterface
|
||||
class JsonStringOutput implements OutputInterface
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return json_encode($array_of_data);
|
||||
return json_encode($arrayOfData);
|
||||
}
|
||||
}
|
||||
|
||||
class OutputArray implements OutputInterface
|
||||
class ArrayOutput implements OutputInterface
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return $array_of_data;
|
||||
return $arrayOfData;
|
||||
}
|
||||
}
|
||||
{% endhighlight %}
|
||||
@@ -203,15 +203,13 @@ behaviour required at runtime:
|
||||
{% highlight php %}
|
||||
<?php
|
||||
|
||||
class SomeClientClass
|
||||
class SomeClient
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct(){}
|
||||
|
||||
public function setOutput(OutputInterface $output_type)
|
||||
public function setOutput(OutputInterface $outputType)
|
||||
{
|
||||
$this->output = $output_type;
|
||||
$this->output = $outputType;
|
||||
}
|
||||
|
||||
public function loadOutput()
|
||||
@@ -227,14 +225,14 @@ that has been set.
|
||||
{% highlight php %}
|
||||
<?php
|
||||
|
||||
$client = new SomeClientClass();
|
||||
$client = new SomeClient();
|
||||
|
||||
// Want an array?
|
||||
$client->setOutput(new OutputArray());
|
||||
$client->setOutput(new ArrayOutput());
|
||||
$data = $client->loadOutput();
|
||||
|
||||
// Want some JSON?
|
||||
$client->setOutput(new OutputJsonString());
|
||||
$client->setOutput(new JsonStringOutput());
|
||||
$data = $client->loadOutput();
|
||||
|
||||
{% endhighlight %}
|
||||
|
Reference in New Issue
Block a user