예제 #1
0
파일: Files.php 프로젝트: ondrakoupil/tools
 /**
  * Ověří, zda soubor je v zadaném adresáři.
  * @param string $file
  * @param string $dir
  * @return bool
  */
 static function isFileInDir($file, $dir)
 {
     if (!Strings::endsWith($dir, "/")) {
         $dir .= "/";
     }
     return Strings::startsWith($file, $dir);
 }
 /**
  * @param $className
  * @return array
  * Get a controller's actions by reflection
  * 通过反射得到我们需要的Controller Class里面的每一个Action(s)
  */
 private function getActionAccessList($className)
 {
     $clz = new ReflectionClass($className);
     $methods = $clz->getMethods(ReflectionMethod::IS_PUBLIC);
     $actions = array();
     foreach ($methods as $method) {
         if ($method->class != $className) {
             continue;
         }
         $methodName = $method->getName();
         if (Strings::endsWith($methodName, 'Action')) {
             $nodeAccess = $this->getActionAccess($method);
             if ($nodeAccess['page']) {
                 array_push($actions, $nodeAccess);
             }
         }
     }
     return $actions;
 }
예제 #3
0
파일: Strings.php 프로젝트: letsdrink/ouzo
 /**
  * Adds suffix to the string, if string does not end with the suffix already.
  *
  * Example:
  * <code>
  * $string = 'Daenerys Targaryen';
  * $stringWithPrefix = Strings::appendMissingSuffix($string, ' Targaryen');
  * </code>
  * Result:
  * <code>
  * Daenerys Targaryen
  * </code>
  *
  * @param string $string
  * @param string $suffix
  * @return string
  */
 public static function appendIfMissing($string, $suffix)
 {
     if (Strings::endsWith($string, $suffix)) {
         return $string;
     }
     return Strings::appendSuffix($string, $suffix);
 }
예제 #4
0
 /**
  * @param mixed $object
  * @param string $methodName
  * @param mixed $default
  * @return mixed
  */
 public static function callMethod($object, $methodName, $default)
 {
     $name = rtrim($methodName, '()');
     if (Strings::endsWith($methodName, '()') && method_exists($object, $name)) {
         $result = $object->{$name}();
         return $result === null ? $default : $result;
     }
     return $default;
 }
예제 #5
0
 /**
  * endsWith() をテストします. 以下を確認します.
  * 
  * - 第 1 引数の文字列の末尾が第 2 引数の文字列に合致した場合に true, それ以外は false を返す
  * - 第 2 引数が空文字列の場合は true を返す
  * - 引数が文字列型でない場合は文字列に変換してから適用する
  * 
  * @covers Peach\Util\Strings::endsWith
  */
 public function testEndsWith()
 {
     $this->assertSame(true, Strings::endsWith("The quick brown fox", "fox"));
     $this->assertSame(false, Strings::endsWith("Hogehoge", "Hoge"));
     $this->assertSame(true, Strings::endsWith("something", ""));
     $suffix = new StringsTest_Object("TEST");
     $subject = new StringsTest_Object("objectTEST");
     $other = new StringsTest_Object("fuga");
     $this->assertSame(true, Strings::endsWith($subject, $suffix));
     $this->assertSame(false, Strings::endsWith($subject, $other));
 }