Example #1
0
 /**
  * Starts the session.
  */
 public function open()
 {
     if ($this->getIsActive()) {
         return;
     }
     @session_start();
     if ($this->getIsActive()) {
         Application::info('Session started', __METHOD__);
     } else {
         $error = error_get_last();
         $message = isset($error['message']) ? $error['message'] : 'Failed to start session.';
         Application::error($message, __METHOD__);
     }
 }
Example #2
0
 /**
  * Get the required parameters. Return bad request if any of them is missing. This method will return array.
  * 
  * @param variable
  * @return array
  * @link http://koldy.net/docs/input#require
  *
  * @example
  * 		$params = Input::requireParamsArray('id', 'email');
  * 		echo $params['email'];
  */
 public static function requireParamsArray()
 {
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'GET':
             $parameters = $_GET;
             break;
         case 'POST':
             $parameters = $_POST;
             break;
         case 'PUT':
         case 'DELETE':
             $parameters = static::getInputVars();
             break;
     }
     $params = func_get_args();
     $a = array();
     foreach ($params as $param) {
         if (!isset($parameters[$param])) {
             if (Application::inDevelopment()) {
                 $passedParams = implode(',', array_keys($parameters));
                 Log::debug("Missing {$_SERVER['REQUEST_METHOD']} parameter '{$param}', only got " . (strlen($passedParams) > 0 ? $passedParams : '[nothing]'));
             }
             Application::error(400, 'Missing one of the parameters');
         }
         $a[$param] = $parameters[$param];
     }
     return $a;
 }
Example #3
0
    // -- down --
    public function down()
    {

    }
}
*/
/**
 * Configuration
 */
require_once __DIR__ . '/../lib/Application.php';
$glyph = new Application();
// Check input
if (empty($argv[1])) {
    //print("Error[01]: No file specified\n");
    $glyph->error(01, 'No file specified');
} else {
    $inputFile = $argv[1];
    print "File: {$inputFile}\n";
    $ext = $glyph->getFileExtension($inputFile);
    if ($ext) {
        if ($ext != 'glyph') {
            print "Error[02]: File extension not .glyph\n";
            return -1;
        }
    } else {
        //$glyph->error();
        print "Error[03]: Cannot find filetype\n";
    }
}
/**
Example #4
0
 /**
  * You can check if configure mail driver is enabled or not.
  * 
  * @param string $driver [optional] will use default if not set
  * @return boolean
  */
 public static function isEnabled($driver = null)
 {
     self::init();
     if ($driver === null) {
         $driver = self::$defaultDriver;
     }
     $config = Application::getConfig('mail');
     if (!isset($config[$driver])) {
         Log::error("Mail driver '{$driver}' is not defined in config");
         Application::error(500, "Mail driver '{$driver}' is not defined in config");
     }
     return $config[$driver]['enabled'];
 }
Example #5
0
$app->register(new Provider\SecurityServiceProvider());
$app->register(new Provider\RememberMeServiceProvider());
$app->register(new Provider\SessionServiceProvider());
$app->register(new Provider\ServiceControllerServiceProvider());
$app->register(new Provider\SwiftmailerServiceProvider());
$userServiceProvider = new MyApp\User\UserServiceProvider();
$app->register($userServiceProvider, array("user.options" => array("userColumns" => array('isEnabled' => 'is_enabled', 'confirmationToken' => 'confirmation_token', 'timePasswordResetRequested' => 'time_password_reset_requested'), 'emailConfirmation' => array('required' => !$app['debug']), 'mailer' => array('fromEmail' => $config['mail'], 'enabled' => !$app['debug']), 'userRoles' => array('ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_USER'), 'templates' => array('layout' => 'baselayout.twig', 'view' => 'user/profile.twig'), 'userClass' => 'MyApp\\Entities\\User')));
$app->mount('/user', $userServiceProvider);
// More config for user auth system
require_once __DIR__ . "/firewall.php";
$app->register(new FormServiceProvider());
$app->register(new DoctrineOrmManagerRegistryProvider());
include __DIR__ . '/common_app.php';
$listener = new \MyApp\Entities\Listeners\NodeLogging($app);
$app['orm.em']->getConfiguration()->getEntityListenerResolver()->register($listener);
$listener = new \MyApp\Entities\Listeners\RelationLogging($app);
$app['orm.em']->getConfiguration()->getEntityListenerResolver()->register($listener);
$listener = new \MyApp\Entities\Listeners\PropertyLogging($app);
$app['orm.em']->getConfiguration()->getEntityListenerResolver()->register($listener);
include __DIR__ . "/controllers/base.php";
//include controllers
include __DIR__ . "/controllers/ajax.php";
//include controllers
$app->mount('import', include 'controllers/import.php');
$app->error(function (\Exception $e, $code) use($app) {
    switch ($code) {
        case 403:
            return new Response($app['twig']->render('errors/403.twig'), $code);
    }
});
return $app;
Example #6
0
 public function testErrorShouldAssociateCallbackForHttpErrors()
 {
     $app = new Application();
     $app->error(function () {
         return 'Error callback';
     });
     $response = new ResponseMock();
     $app->run(Request::create(false, 'localhost', '/unknown-route'), $response);
     $this->assertEquals('404 Not Found', $response->status());
     $this->assertEquals('Error callback', $response->contents());
 }
Example #7
0
 /**
  * Construct the object
  * 
  * @param array $params array of parameter definitions
  */
 public function __construct(array $params)
 {
     $this->input = $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET;
     foreach ($params as $param => $validators) {
         if ($validators === null) {
             if (isset($this->input[$param])) {
                 $v = trim($this->input[$param]);
                 if (strlen($v) > 0) {
                     $this->valids[$param] = $v;
                 } else {
                     $this->valids[$param] = null;
                 }
             } else {
                 $this->valids[$param] = null;
             }
         } else {
             $validators = explode('|', $validators);
             foreach ($validators as $validator) {
                 if (!isset($this->invalids[$param])) {
                     $colonPos = strpos($validator, ':');
                     if ($colonPos !== false) {
                         $method = substr($validator, 0, $colonPos);
                         $settings = substr($validator, $colonPos + 1);
                     } else {
                         $method = $validator;
                         $settings = null;
                     }
                     $method = str_replace(' ', '', ucwords(str_replace('_', ' ', trim($method))));
                     $method = "validate{$method}";
                     $result = $this->{$method}($param, $settings);
                     if ($result !== true) {
                         $this->invalids[$param] = $result;
                     } else {
                         if (isset($this->input[$param])) {
                             if (!is_array($this->input[$param])) {
                                 $value = trim($this->input[$param]);
                                 $this->valids[$param] = $value == '' ? null : $value;
                             } else {
                                 $this->valids[$param] = $this->input[$param];
                             }
                         } else {
                             $this->valids[$param] = null;
                         }
                     }
                 }
             }
         }
     }
     if (sizeof($this->badRequest) > 0) {
         Log::warning('Missing parameters: ' . implode(', ', $this->badRequest));
         Application::error(400, 'Bad request. Missing parameters');
     }
 }
Example #8
0
$app->register(new \Silex\Provider\ValidatorServiceProvider());
/**
 * Twig Register
 */
$app->register(new \Silex\Provider\TwigServiceProvider(), ['twig.path' => __DIR__ . "/views", 'twig.form.templates' => ['livetext/form/bootstrap.html.twig'], 'twig.options' => ['cache' => $app['debug'] ? null : __DIR__ . '/cache']]);
/**
 * URL Generator Register
 */
$app->register(new \Silex\Provider\UrlGeneratorServiceProvider());
/**
 * Translation Register
 */
$app->register(new \Silex\Provider\TranslationServiceProvider());
/**
 * LiveTex Register
 */
$app->register(new \LiveTextBundle\LiveTextProvider(), ['livetext.controller.basepath' => '/', 'asset.webpath.css' => '/public/css', 'asset.webpath.js' => "/public/js"]);
if (php_sapi_name() === 'cli') {
    $app->register(new \Knp\Provider\ConsoleServiceProvider(), ['console.name' => 'LiveText Tools', 'console.version' => '1.0.0', 'console.project_directory' => __DIR__ . "/.."]);
    $app->register(new \Dbtlr\MigrationProvider\Provider\MigrationServiceProvider(), ['db.migrations.path' => __DIR__ . "/migrations", 'db.migrations.table_name' => 'migration_versions']);
    $console = $app['console'];
    $app['console']->add(new \LiveTextBundle\Command\FakePerson());
    $console->run();
} else {
    $app->error(function (\Exception $e, $code) {
        if ($code === 404) {
            return new \Symfony\Component\HttpFoundation\Response($e->getMessage(), 404);
        }
    });
    $app->run();
}