コード例 #1
0
ファイル: CreateCommand.php プロジェクト: core-framework/core
 private function formatName($name, $fileType)
 {
     if (strContains($fileType, $name)) {
         $name = str_replace($fileType, '', strtolower($name));
     }
     $name = $name . ucfirst($fileType);
     return $name;
 }
コード例 #2
0
ファイル: SeederCommand.php プロジェクト: core-framework/core
 private function runClass($class)
 {
     if (!strContains('\\', $class)) {
         $namespacedClass = $this->namespace . '\\' . $class;
     } else {
         $namespacedClass = $class;
     }
     /** @var AbstractSeeder $seeder */
     $seeder = new $namespacedClass($this->application()->getMapper());
     $seeder->run();
     $this->io->writeln("Seeding of {$class} completed Successfully", 'green');
 }
コード例 #3
0
ファイル: functions.php プロジェクト: bderudder/oneplus_data
/**
 * Add a new user in the database.
 * @return true if the user was added, otherwise false.
 */
function addNewUserInDB($username, $email, $invite_url)
{
    if ($connection = connectDB()) {
        if (!checkIfUserExists($connection, $username)) {
            $userStats = fetchUserStatsFromKid($invite_url);
            if (!strContains($userStats, 'error')) {
                $query = "INSERT INTO users(displayname, rank, referrals, email, invite_url) VALUES (?, ?, ?, ?, ?)";
                $stmt = $connection->stmt_init();
                $stmt->prepare($query);
                $stmt->bind_param("siiss", $username, explode(';', $userStats)[0], explode(';', $userStats)[1], $email, $invite_url);
                $stmt->execute();
                $connection->close();
                return true;
            }
        }
        $connection->close();
    }
    return false;
}
コード例 #4
0
ファイル: IOStream.php プロジェクト: core-framework/core
 /**
  * Prints error message with specific formatting
  *
  * @param string $msg
  * @param string|\Exception $exception
  * @throws \ErrorException
  */
 public function showErr($msg, $exception = null)
 {
     $format = "\n%s\n\n";
     $lines = [];
     $lines[] = " ";
     if ($exception instanceof \Exception) {
         $lines[] = "[" . $exception->getCode() . "][" . get_class($exception) . "]";
     } elseif (!is_null($exception)) {
         $lines[] = "[" . (string) $exception . "]";
     }
     if (strContains("\n", $msg)) {
         $_lines = explode("\n", $msg);
         $lines[] = " ";
         foreach ($_lines as $line) {
             $lines[] = $line;
         }
         $lines[] = " ";
     } else {
         $lines[] = " ";
         $lines[] = $msg;
         $lines[] = " ";
     }
     $formattedLinesArr = $this->addPadding($lines, 5);
     $formattedLinesArr = $this->addPadding($formattedLinesArr, 5, STR_PAD_LEFT);
     $coloredLinesArr = $this->getColoredLines($formattedLinesArr, 'white', 'red', 'bold');
     $styledLines = implode(PHP_EOL, $coloredLinesArr);
     fprintf(static::$output, $format, $styledLines);
 }
コード例 #5
0
ファイル: MySqlMapper.php プロジェクト: core-framework/core
 /**
  * {@inheritdoc}
  */
 public function execute($sql, $params = [])
 {
     $isSelect = strContains('select', $sql);
     if (!empty($params)) {
         $prepared = $this->getPrepared($sql);
         $result = $prepared->execute($params);
         if ($result === false && $this->getConnection()->errorCode() !== '00000') {
             throw new \PDOException("SQL Error: {$this->getConnection()->errorCode()} : {$this->getConnection()->errorInfo()[2]}");
         }
         if ($isSelect) {
             return $prepared->fetchAll(\PDO::FETCH_ASSOC);
         } else {
             return $result;
         }
     } else {
         $result = $this->query($sql);
         if ($result === false && $this->getConnection()->errorCode() !== '00000') {
             throw new \PDOException("SQL Error: {$this->getConnection()->errorCode()} : {$this->getConnection()->errorInfo()[2]}");
         }
         if ($isSelect) {
             return $result->fetchAll(\PDO::FETCH_ASSOC);
         } else {
             return $result;
         }
     }
 }
コード例 #6
0
ファイル: Request.php プロジェクト: core-framework/core
 /**
  * @inheritdoc
  */
 public function isJson()
 {
     return strContains('json', $this->headers->get('Content-Type'));
 }
コード例 #7
0
ファイル: Dispatcher.php プロジェクト: core-framework/core
 /**
  * @param $subscriber
  * @return Subscriber
  * @throws \ErrorException
  */
 protected function makeSubscriber($subscriber)
 {
     if (is_string($subscriber) && !strContains('\\', $subscriber)) {
         return $this->container->get($subscriber);
     } elseif (is_string($subscriber) && strContains('\\', $subscriber)) {
         return $this->container->make($subscriber);
     } elseif (is_object($subscriber) && $subscriber instanceof Subscriber) {
         return $subscriber;
     } else {
         throw new \InvalidArgumentException("Subscriber must be a valid Service name or Class name implementing Subscribe Interface");
     }
 }
コード例 #8
0
ファイル: email.php プロジェクト: slab-php/slab
 function __check_referer()
 {
     return !empty($_SERVER['HTTP_REFERER']) || !strContains($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']);
 }
コード例 #9
0
ファイル: View.php プロジェクト: core-framework/core
 /**
  * @param $variable
  * @param $value
  */
 public function set($variable, $value)
 {
     if (strContains('.', $variable)) {
         $this->dotAssign($variable, $value);
     } else {
         $this->getEngine()->assign($variable, $value);
     }
 }
コード例 #10
0
 /**
  * Get real path from provided aliased path
  *
  * @param $aliasPath
  * @return string
  */
 public function getRealPath($aliasPath)
 {
     if (!strContains('@', $aliasPath)) {
         return $aliasPath;
     }
     $alias = substr($aliasPath, 0, strpos($aliasPath, '/'));
     $relativePath = substr($aliasPath, strpos($aliasPath, '/'));
     $realPath = $this->getAlias($alias) . $relativePath;
     if (!is_dir($realPath) && substr($realPath, -1) != '/') {
         $realPath .= '.php';
     }
     return $realPath;
 }
コード例 #11
0
ファイル: Router.php プロジェクト: core-framework/core
 /**
  * Wraps the controller or function into a callable closure
  *
  * @param RouteInterface $route
  * @return \Closure
  * @throws \HttpRuntimeException
  */
 protected function getNextCallable(RouteInterface $route)
 {
     $controller = $route->getController();
     $controllerMethod = $route->getControllerMethod();
     $namespace = $this->getControllerNamespace();
     $payload = $route->getRouteParameters();
     if (is_callable($controller)) {
         $args = $this->getFunctionArgs($controller);
         $next = function () use($controller, $args) {
             return call_user_func_array($controller, $args);
         };
     } else {
         if (strContains('\\', $controller)) {
             $class = $controller;
         } else {
             $class = $namespace . '\\' . $controller;
         }
         if (class_exists($class, true)) {
             $obj = $this->makeController($class);
             $obj->setApplication($this->application);
             $args = $this->getFunctionArgs($controller, $controllerMethod);
             $next = function () use($obj, $args, $controllerMethod, $payload) {
                 return $this->runController($obj, $controllerMethod, $args);
             };
         } else {
             throw new ControllerNotFoundException();
         }
     }
     return $next;
 }
コード例 #12
0
 private function migrateRun($namespacedClass, $class)
 {
     $save = false;
     /** @var AbstractMigration $migrationClass */
     $migrationClass = new $namespacedClass($this->application()->getMapper());
     $migrationClass->{$this->direction}();
     if (strContains($this->namespace, $namespacedClass)) {
         $migrationName = $class;
     } else {
         $migrationName = $namespacedClass;
     }
     $migrationModel = Migration::findOne(['migration' => $migrationName]);
     if (!$migrationModel) {
         $migrationModel = new Migration(['migration' => $migrationName, 'batch' => 0]);
         $save = true;
     }
     if ($this->direction === 'up') {
         $migrationModel->batch++;
     } elseif ($this->direction === 'down' && $migrationModel->count !== 0) {
         $migrationModel->batch--;
     }
     if ($save) {
         return $migrationModel->save();
     } else {
         return $migrationModel->update();
     }
 }
コード例 #13
0
 /**
  *
  */
 public function testCheckForUniqueWithInvalidData()
 {
     // This time we'll mock the entire Validator class and test that instead of an actual
     // instance of the class. We specify setMethods, so ONLY specified methods are stubbed. All others are mocked,
     // and will run the code behind them. Stubbed can be overridden, and return null by default
     $validator = $this->getMockBuilder('Acme\\Validation\\Validator')->setConstructorArgs([$this->request, $this->response, $this->session])->setMethods(['getRows'])->getMock();
     $validator->method('getRows')->willReturn(['a']);
     $errors = $validator->check(['my_field' => 'unique:User']);
     $error_msg = $errors[0];
     $this->assertTrue(strContains($error_msg, "already exists in this system"));
 }
コード例 #14
0
 /**
  * Finds closest command matching input (typo) string
  *
  * @param array $argv
  * @return bool
  */
 public function closestCommand(array $argv)
 {
     $keys = array_keys($this->commands);
     $found = false;
     foreach ($keys as $i => $key) {
         if ((strContains($argv[0], $key) || strContains($key, $argv[0])) && $found === false) {
             $found = $key;
         }
     }
     return $found;
 }
コード例 #15
0
ファイル: Container.php プロジェクト: core-framework/core
 /**
  * @param string|object $namespacedClass
  * @param bool|mixed $fail
  * @return bool|mixed
  */
 public static function findInstance($namespacedClass, $fail = false)
 {
     try {
         if (!strContains('\\', $namespacedClass) && static::serviceExists($namespacedClass)) {
             return self::get($namespacedClass);
         } elseif (!strContains('\\', $namespacedClass) && !static::serviceExists($namespacedClass)) {
             return $fail;
         }
         $reflection = new \ReflectionClass($namespacedClass);
         $class = $reflection->getShortName();
         $namespacedClass = $reflection->getName();
         // search by class name
         if (self::serviceExists($class)) {
             $object = self::get($class);
             if ($object instanceof $namespacedClass) {
                 return $object;
             }
         }
         // search shared instances
         foreach (static::$sharedInstances as $name => $instance) {
             if ($instance instanceof $namespacedClass) {
                 return $instance;
             }
         }
         // search services
         foreach (static::$services as $name => $service) {
             $instance = self::get($name);
             if ($instance instanceof $namespacedClass) {
                 return $instance;
             }
         }
     } catch (\Exception $e) {
         return $fail;
     }
     return $fail;
 }