Просмотр исходного кода

:octocat: added container trait

smiley 8 лет назад
Родитель
Сommit
964f9be90c
3 измененных файлов с 70 добавлено и 0 удалено
  1. 66 0
      src/Container.php
  2. 3 0
      src/Output/QROutputOptionsAbstract.php
  3. 1 0
      src/QROptions.php

+ 66 - 0
src/Container.php

@@ -0,0 +1,66 @@
+<?php
+/**
+ * Trait Container
+ *
+ * @filesource   Container.php
+ * @created      09.07.2017
+ * @package      chillerlan\QRCode
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCode;
+
+/**
+ * a generic container with getter and setter
+ * @codeCoverageIgnore
+ */
+trait Container{
+
+	/**
+	 * Boa constructor.
+	 *
+	 * @param array $properties
+	 */
+	public function __construct(array $properties = []){
+
+		foreach($properties as $key => $value){
+			$this->__set($key, $value);
+		}
+
+	}
+
+	/**
+	 * David Getter
+	 *
+	 * @param string $property
+	 *
+	 * @return mixed
+	 */
+	public function __get(string $property){
+
+		if(property_exists($this, $property)){
+			return $this->{$property};
+		}
+
+		return false;
+	}
+
+	/**
+	 * Jet-setter
+	 *
+	 * @param string $property
+	 * @param mixed  $value
+	 *
+	 * @return void
+	 */
+	public function __set(string $property, $value){
+
+		if(property_exists($this, $property)){
+			$this->{$property} = $value;
+		}
+
+	}
+
+}

+ 3 - 0
src/Output/QROutputOptionsAbstract.php

@@ -12,10 +12,13 @@
 
 
 namespace chillerlan\QRCode\Output;
 namespace chillerlan\QRCode\Output;
 
 
+use chillerlan\QRCode\Container;
+
 /**
 /**
  *
  *
  */
  */
 abstract class QROutputOptionsAbstract{
 abstract class QROutputOptionsAbstract{
+	use Container;
 
 
 	public $type;
 	public $type;
 
 

+ 1 - 0
src/QROptions.php

@@ -16,6 +16,7 @@ namespace chillerlan\QRCode;
  *
  *
  */
  */
 class QROptions{
 class QROptions{
+	use Container;
 
 
 	/**
 	/**
 	 * @var int
 	 * @var int