예제 #1
0
 public function __call($name, $args)
 {
     if (StringUtil::startsWith($name, 'set') && !StringUtil::endsWith($name, 'Id')) {
         $property = strtolower(preg_replace('/([a-z])([A-Z])/', '${1}_${2}', substr($name, 3)));
         if (property_exists($this, $property) && count($args) == 1) {
             $this->{$property} = $args[0];
             return $this;
         }
     }
     throw new ModelException(sprintf('The method %s does not exist on the model %s, and cannot be magically created', $name, get_class($this)));
 }
예제 #2
0
 public function testStartsWith()
 {
     $string = 'ah !';
     $this->assertTrue(StringUtil::startsWith($string, ''));
     $this->assertTrue(StringUtil::startsWith($string, 'a'));
     $this->assertTrue(StringUtil::startsWith($string, 'ah'));
     $this->assertTrue(StringUtil::startsWith($string, 'ah '));
     $this->assertTrue(StringUtil::startsWith($string, 'ah !'));
     $this->assertFalse(StringUtil::startsWith($string, ' '));
     $this->assertFalse(StringUtil::startsWith($string, 'h !'));
     $this->assertFalse(StringUtil::startsWith($string, false));
     $this->assertFalse(StringUtil::startsWith($string, true));
 }
 public function testGetCallStack()
 {
     try {
         $this->instanceFunction();
         $this->fail();
     } catch (Exception $e) {
         $formatter = new ExceptionFormatter($e);
     }
     $calls = $formatter->getCallStack();
     $this->assertTrue(StringUtil::startsWith($calls[0], 'function genericFuncion()'));
     $this->assertTrue(StringUtil::startsWith($calls[1], 'ExceptionFormatterTest::{closure}()'));
     $this->assertTrue(StringUtil::startsWith($calls[2], 'ExceptionFormatterTest::staticFunction()'));
     $this->assertTrue(StringUtil::startsWith($calls[3], 'ExceptionFormatterTest->instanceFunction()'));
 }
예제 #4
0
 /**
  * Use the route defined by $routeName to encode $params and return a valid path
  *
  * @param string $routeName The name of the route to use
  * @param array $params The params to use in the path
  * @return string The path
  * @throws InvalidParamException If there is something wrong with the params
  * @throws MalformedPathException If the generated path is malformed
  * @throws MissingParamException If one or more required params are missing
  * @throws UnknownRouteException If there's no route for $routeName
  */
 public function encode($routeName, array $params = array())
 {
     if (!isset($this->routes[$routeName])) {
         throw new UnknownRouteException(sprintf('Unknown route %s', $routeName));
     }
     /** @var $route IRoute */
     $route = $this->routes[$routeName];
     $path = $route->encode($params);
     // Making sure that the path starts with /
     if (!StringUtil::startsWith($path, '/')) {
         throw new MalformedPathException(sprintf('The generated path must start with /, instead it was: %s', $path));
     }
     return $path;
 }