本文整理汇总了PHP中Assert\Assertion::ClassExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Assertion::ClassExists方法的具体用法?PHP Assertion::ClassExists怎么用?PHP Assertion::ClassExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assert\Assertion
的用法示例。
在下文中一共展示了Assertion::ClassExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContainer
private function createContainer()
{
$container = new ContainerBuilder();
// retrieve security class
$values = \Parameters::get('security');
$class = $values['security']['classes'];
$session_name = $values['session']['name'];
// test if class exist and implement interface
try {
Assertion::ClassExists($class);
Assertion::implementsInterface($class, '\\GL\\Core\\Security\\AuthenticationServiceInterface');
} catch (AssertionFailedException $e) {
echo $e->getMessage();
die;
}
// Inject mailer
$container->register('mailer', 'GL\\Core\\Tools\\Mailer');
// Inject Request
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setFactory("Symfony\\Component\\HttpFoundation\\Request::createFromGlobals");
// Inject Request helper
$container->register('request_helper', 'GL\\Core\\Helpers\\RequestHelper')->addMethodCall('setRequest', array(new Reference('request')));
// Inject Twig Service
$container->register('template', 'GL\\Core\\Templating\\TemplateProvider');
// Inject RouteCollection
$container->register('routes', 'Symfony\\Component\\Routing\\RouteCollection')->setFactory("GL\\Core\\Routing\\RouteProvider::GetRouteCollection");
if (class_exists("\\PHPExcel")) {
// Inject PHPExcel Wrapper
$container->register('excel', 'GL\\Core\\Tools\\Excel');
}
if (class_exists("\\TCPDF")) {
// Inject FPDF Wrapper
$container->register('pdf', 'GL\\Core\\Tools\\PDF');
}
// Inject Session
$container->register('session', 'Symfony\\Component\\HttpFoundation\\Session\\Session')->addMethodCall('setName', array($session_name))->addMethodCall('start');
// Inject Crsf verifier
$container->register('crsf', 'GL\\Core\\Security\\FormCrsf')->addArgument(new Reference('session'))->addArgument(new Reference('request'));
// Inject translator service
$container->register('translator', 'GL\\Core\\Config\\Translator');
// Inject Security Service
$container->register('security', $class)->addArgument(new Reference('session'))->addArgument(new Reference('request'))->addMethodCall('autologin');
// Inject DebugBar
$container->register('debug', 'GL\\Core\\Debug\\KLDebugBar');
// Inject Pdo Object
$container->register('pdo', 'PDO')->setFactory("GL\\Core\\Helpers\\DbHelper::getPdo");
// Inject Config
$container->register('config', 'GL\\Core\\Config\\Config');
// Inject DbHelper
$container->register('db', 'GL\\Core\\Helpers\\DbHelper');
// Inject Redis
$container->register('redis', 'GL\\Core\\Tools\\Redis');
// Inject services defined in config/services.yml
$loader = new YamlFileLoader($container, new FileLocator(SERVICEPATH));
$loader->load('services.yml');
$container->compile();
return $container;
}
示例2: testTwig
private function testTwig()
{
try {
$class = "Twig_Environment";
Assertion::ClassExists($class);
} catch (AssertionFailedException $e) {
echo "Twig is not installed, add it with 'twig/twig':'1.24' in your composer.json";
die;
}
}
示例3: getTemplateService
public function getTemplateService($eng = "")
{
$ret = null;
// spécify engine or use default
$engine = $eng == "" ? TEMPLATE_ENGINE : $eng;
try {
Assertion::keyIsset($this->arr, $engine, "Template engine {$engine} is not defined");
$class = $this->arr[$engine];
Assertion::ClassExists($class);
$ret = new $class();
} catch (Exception $e) {
}
return $ret;
}
示例4: getInstance
/**
*
* Return a controller instance
*
* @param String $controllername Controller namespace to instanciate
* @return \GL\Core\Controller\Controller Herited instance of controller
*/
private function getInstance($controllername)
{
try {
Assertion::ClassExists($controllername);
} catch (AssertionFailedException $e) {
echo "Error class {$controllername} does not exists";
die;
}
$instance = new $controllername($this->_controller, $this->_action);
// add dependency container in the controller instance
$instance->setContainer($this->_container);
return $instance;
}
示例5: run
private function run($instance, $type = "up")
{
// test if class exist and implement interface
try {
$class = get_class($instance);
Assertion::ClassExists($class);
Assertion::implementsInterface($class, '\\GL\\Core\\Migration\\MigrationInterface');
$max = 0;
// get all migrations in db
$migrations = MigrationModel::all();
// find max batch id version
if (count($migrations) > 0) {
$max = $migrations->max('db_version');
}
$batchid = $max + 1;
// retrieve className
$id = $instance->getUniqueTag();
// find if this instance was not executed
$exec = MigrationModel::where('migration', '=', $id)->first();
$bExec = true;
if ($exec != null) {
if ($exec->status == $type) {
// always executed
$bExec = false;
}
}
if ($bExec) {
$instance->{$type}();
// insert in db
if ($exec == null) {
$exec = new MigrationModel();
}
$exec->class = $class;
$exec->migration = $id;
$exec->status = $type;
$exec->db_version = $batchid;
$exec->save();
}
} catch (\Exception $ex) {
echo $ex;
} catch (AssertionFailedException $e) {
echo $e;
}
}
示例6: executeBefores
/**
* Function execute before action execute
* @param string $route actual route
* @return boolean
*/
public function executeBefores($route)
{
$ret = false;
$fnArray = \Functions::getAll();
if (isset($fnArray)) {
foreach ($fnArray as $key => $value) {
if ($value["type"] == "before") {
// for each global function defined
$arrRoutes = isset($value["routes"]) ? $value["routes"] : null;
$scope = isset($value["scope"]) ? $value["scope"] : "all";
$class = $value["class"];
// test if class exist and implements interface
Assertion::ClassExists($class);
Assertion::implementsInterface($class, '\\GL\\Core\\Controller\\BeforeFunctionInterface');
$bExecute = $this->IsAllowed($arrRoutes, $route, $scope);
if ($bExecute) {
$exc = new $class($this->_container);
$ret = $exc->execute();
}
}
}
}
return $ret;
}