Example #1
0
 /**
  * Function to use other defined abstract methods to 
  * use a standard naming-convention based method of 
  * building classes by the factory
  * 
  * @return mixed - anything a subclass factory can build
  */
 public function build()
 {
     //get the driver to build
     $driver = $this->getDriverConfigValue();
     //return null if there's nothing to build.
     if (is_null($driver)) {
         return null;
     }
     //get the prefix, suffix and namespace for the driver class
     $prefix = $this->getDriverNamePrefix();
     $suffix = $this->getDriverNameSuffix();
     $ns = $this->getDriverNamespace();
     //use naming convention to convert the driver name
     //into a fully quantified class name
     $klass = Str::studly($driver);
     $fqcn = "{$ns}\\{$prefix}{$klass}{$suffix}";
     try {
         $refl = new \ReflectionClass($fqcn);
     } catch (\ReflectionException $e) {
         throw new \InvalidArgumentException("Unsupported driver [{$driver}] to load [{$fqcn}]");
     }
     //make sure the driver implements the interface properly
     $interface = $this->getDriverInterface();
     if (!$refl->implementsInterface($interface)) {
         throw new \InvalidArgumentException("Unsupported interface [{$driver}] must implement [{$interface}]");
     }
     $instance = $refl->newInstanceArgs($this->getDriverArgumentsArray());
     if (is_null($instance)) {
         throw new \InvalidArgumentException("Driver [{$driver}] failed to create an instance");
     }
     return $instance;
 }
Example #2
0
 public function testStringMacros()
 {
     Trucker\Support\Str::macro(__CLASS__, function () {
         return 'foo';
     });
     $this->assertEquals('foo', Str::SupportStrTest());
 }
 /**
  * Function to return a boolean value indicating whether
  * the provided status is matched by the configured setting.
  *
  * Currently supports:
  *
  * @param $option
  * @param $status
  *
  * @return bool
  */
 protected function matchesStatus($option, $status)
 {
     $configValue = Config::get($option);
     if (is_array($configValue)) {
         return Config::contains($option, $status);
     }
     return Str::is($configValue, $status);
 }
Example #4
0
 public function testLength()
 {
     $this->assertEquals(4, Str::length("test"));
 }