public function sf_debug($o, $exit = true) { \Dev::dump($o, 8); if ($exit) { exit; } }
public function __construct(ContainerInterface $container, $cache_path, $expired_file) { $this->container = $container; $this->sf_domain = $container->getParameter('sf.admin.domain'); $cache_expired = $this->isCacheExpired($cache_path, $expired_file); $is_debug = $container->getParameter('kernel.debug'); if ($cache_expired && 'cli' !== PHP_SAPI && !$is_debug) { \Dev::dump($cache_expired); exit; } if ($cache_expired) { $container->get('sf.admin.generator'); } $cache = (include $cache_path); foreach ($cache as $i => $_cache) { if ($i) { foreach ($_cache as $_key => $value) { $this->_loader_cache[$_key] = unserialize($value); } } else { foreach ($_cache as $_key => $value) { $this->_loader_cache[$_key] = $value; } } } }
public function getRootPageObject($object = null, \Symforce\AdminBundle\Entity\Page $object_page = null) { $page_admin = $this->getPageAdmin(); $root_page = null; if ($object) { if (!$object_page) { $object_page = $this->getPageObject($object); } $root_page = $page_admin->getReflectionProperty($page_admin->tree['parent'])->getValue($object_page); } else { if ($object_page) { throw new \Exception("big error, need object with object page"); } } if ($this->page_parent_entity) { $parent_admin = $this->admin_loader->getAdminByClass($this->page_parent_entity); if ($this->route_parent !== $parent_admin) { throw new \Exception("big error, page parent admin should be the route admin"); } $parent_object = null; if ($object) { $parent_object = $this->getReflectionProperty($this->property_page_name)->getValue($object); } else { $parent_object = $parent_admin->getObject(); if (!$parent_object) { throw new \Exception("big error, page parent admin should have object"); } } if (!$root_page) { $root_page = $parent_admin->getPageObject($parent_object); } else { // fix|check root page \Dev::dump($root_page); exit; } } else { if (!$root_page) { $root_page = $page_admin->getRepository()->findOneBy(array('admin_enabled' => true, 'admin_is_root' => true, 'admin_entity_id' => 0, 'admin_class' => $this->class_name, 'admin_page_property' => $this->property_page_name)); } if (!$root_page) { $root_page = $page_admin->newObject(); $root_page->admin_class = $this->class_name; $root_page->admin_page_property = $this->property_page_name; $root_page->admin_enabled = true; } $root_page->admin_is_root = true; $root_page->admin_entity_id = 0; if ($this->page_route_parent) { // $root_page->admin_route_parent = $this->page_route_parent ; } } if (null === $root_page->title) { $root_page->title = $this->getLabel(); } if ($object_page) { $page_admin->getReflectionProperty($page_admin->tree['parent'])->setValue($object_page, $root_page); } return $root_page; }
/** * Returns an empty user instance * * @return UserInterface */ public function createUser() { $class = $this->getClass(); $user = new $class(); \Dev::dump($user); exit; return $user; }
protected function crateForm(\Symfony\Component\HttpFoundation\Request $request) { $tr = $this->container->get('translator'); $sf_domain = $this->container->getParameter('sf.admin.domain'); $builder = $this->container->get('form.factory')->createNamedBuilder('login', 'form', array('label' => 'sf.login.label', 'translation_domain' => $sf_domain)); $builder->add('username', 'text', array('label' => 'sf.login.username.label', 'translation_domain' => $sf_domain, 'data' => $request->getSession()->get(Security::LAST_USERNAME), 'horizontal_input_wrapper_class' => 'col-xs-6', 'attr' => array('placeholder' => 'sf.login.username.placeholder')))->add('password', 'password', array('label' => 'sf.login.password.label', 'translation_domain' => $sf_domain, 'horizontal_input_wrapper_class' => 'col-xs-6', 'attr' => array()))->add('captcha', 'sf_captcha', array('label' => 'sf.form.captcha.label', 'translation_domain' => $sf_domain)); $form = $builder->getForm(); if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) { $error = $request->attributes->get(Security::AUTHENTICATION_ERROR); } else { $error = $request->getSession()->get(Security::AUTHENTICATION_ERROR); $request->getSession()->set(Security::AUTHENTICATION_ERROR, null); } if ($error) { if ($error instanceof \Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException) { $_error = $tr->trans('sf.login.error.crsf', array(), $sf_domain); $form->addError(new \Symfony\Component\Form\FormError($_error)); } else { if ($error instanceof \Symforce\UserBundle\Exception\CaptchaException) { $_error = $tr->trans('sf.login.error.captcha', array(), $sf_domain); if ($this->container->getParameter('kernel.debug')) { $_error .= sprintf(" code(%s)", $error->getCode()); } $form->get('captcha')->addError(new \Symfony\Component\Form\FormError($_error)); } else { if ($error instanceof \Symfony\Component\Security\Core\Exception\BadCredentialsException) { $_error = $tr->trans('sf.login.error.credentials', array(), $sf_domain); $form->get('username')->addError(new \Symfony\Component\Form\FormError($_error)); } else { if ($error instanceof \Symfony\Component\Security\Core\Exception\DisabledException) { $_error = $tr->trans('sf.login.error.disabled', array(), $sf_domain); $form->get('username')->addError(new \Symfony\Component\Form\FormError($_error)); } else { $_error = $error->getMessage(); if ($this->container->getParameter('kernel.debug')) { \Dev::dump($error); } $form->get('username')->addError(new \Symfony\Component\Form\FormError($_error)); } } } } } return $form; }
public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserById($token->getUserId()); if ($user && $token instanceof UserToken) { $token->setUser($user); global $_G; $em = \Dev::getDoctrine()->getManager(); $user->setupDiscuzRoles($em, $_G); return $token; } if (\Dev::getContainer()->getParameter('kernel.debug')) { throw new AuthenticationException('The app authentication failed.'); } else { if (\Dev::getContainer()->getParameter('debug_redirects')) { \Dev::dump('The app authentication failed.'); exit; } $host = \Dev::getContainer()->getParameter('sf.web_host'); header('location:' . $host); exit; } }
public function getFormOptions() { $_options = parent::getFormOptions(); $map = $this->admin_object->orm_metadata->getAssociationMapping($this->class_property); /* $admin = $this->admin_object->generator->getAdminByClass( $map['targetEntity'] ) ; */ if (null !== $this->choice_code) { $_options['sf_form_type'] = 'sf_entity'; $_options['entity_class'] = $map['targetEntity']; } else { if (null !== $this->choice_code) { \Dev::dump($this->choice_code); exit; } else { $_options['class'] = $map['targetEntity']; if (null !== $this->group_by) { $_options['group_by'] = $this->group_by; } } } return $_options; }
/** * @Route("/{slug}/apply", name="loan_apply", requirements={"slug":"\w+"} ) * @Template() */ public function applyAction(Request $request, $slug) { $fund = $this->getUseOfFundsAdmin()->getRepository()->findOneBy(array('slug' => $slug)); if (!$fund) { throw $this->createNotFoundException(); } $admin = $this->getLoanAdmin(); $form = $this->createApplyFrom($admin, $fund); $dispatcher = $this->container->get('event_dispatcher'); $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request); $dispatcher->dispatch('sf.event.form', $event); if (null !== $event->getResponse()) { return $event->getResponse(); } if ('POST' === $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $object = $form->getData(); \Dev::dump($object); exit; } } return array('found' => $fund, 'form' => $form->createView(), 'page' => $fund->page); }
public final function connect() { if ($this->_connected) { return; } if ($this->_clear_cache_on_connected) { include_once libfile('function_cache', 'function'); updatecache(array('plugin', 'setting', 'styles')); cleartemplatecache(); cleartemplatecache(); } /** * @var $security_context \Symfony\Component\Security\Core\SecurityContext */ $security_context = $this->_container->get('security.context'); global $_G; if (isset($_G['uid']) && $_G['uid'] > 0 && $_G['uid'] < 0x7fffffff) { $em = $this->_container->get('doctrine')->getManager(); /** * @var $user \Symforce\DiscuzBundle\Entity\User */ $user = $em->getRepository('Symforce\\DiscuzBundle\\Entity\\User')->find($_G['uid']); if (!$user) { throw new \Exception(sprintf('user(id=%s) not exists!', $_G['uid'])); } $user->setupDiscuzRoles($em, $_G); $token = new \Symforce\DiscuzBundle\Security\Authentication\Token\UserToken(); $token->setUser($user); $token->setUserId($user->getId()); $security_context->setToken($token); } $request = \Dev::getRequest(); if ($request->query->has('debug') && 0) { /** * @var $http_kernel \Symfony\Component\HttpKernel\HttpKernel */ $http_kernel = $this->_container->get('http_kernel'); $event = new \Symfony\Component\HttpKernel\Event\GetResponseEvent($http_kernel, $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST); $rc = new \ReflectionObject($http_kernel); $rp = $rc->getProperty('dispatcher'); $rp->setAccessible(true); /** * @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ $dispatcher = $rp->getValue($http_kernel); $dispatcher->dispatch(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, $event); } if ($this->_container->getParameter('kernel.debug')) { if ($request->query->has('debug_dump')) { $debug = $request->query->get('debug_dump'); if (strrpos($debug, '[') !== false) { $accessor = new \Symfony\Component\PropertyAccess\PropertyAccessor(false, true); $value = $accessor->getValue($GLOBALS, $debug); \Dev::dump($value); exit; } } } /** * @var $plugin_module PluginModule */ foreach ($this->_modules as $plugin_module) { $plugin_module->connect(); } $this->_connected = true; }
public function getAdminParentRoutePath(array &$path) { $this->fixAdminRouteParent(); if ($this->route_parent) { if (!is_string($this->route_parent_property)) { \Dev::dump($this); exit; } array_unshift($path, $this->route_parent->getName() . '.' . $this->route_parent_property); $this->route_parent->getAdminParentRoutePath($path); } }
public function __construct(\Symforce\AdminBundle\Compiler\Generator\AnnotationCache $cache, $bundle_name, ClassMetadata $meta, Generator $gen) { $this->cache = $cache; $this->bundle_name = $bundle_name; $this->class_name = $cache->class_name; $this->reflection = $meta->getReflectionClass(); $this->generator = $gen; $this->orm_metadata = $meta; if ($meta->isIdentifierComposite) { // @TODO add Composite route handle } else { $this->property_id_name = $meta->getSingleIdentifierFieldName(); } $this->setMyPropertie($cache->class_annotations['Symforce\\AdminBundle\\Compiler\\Annotation\\Entity']); if (!$this->name) { $this->name = strtolower(preg_replace('/\\W/', '_', $this->class_name)); } $this->template = $this->name . '.admin.html.twig'; $this->_template_path = $this->generator->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template; if (null === $this->_final_template) { $tempalte = $this->bundle_name . ':' . basename(str_replace('\\', '\\/', $this->class_name)) . ':admin.macro.html.twig'; try { $this->generator->loadTwigTemplatePath($tempalte); $this->_final_template = $tempalte; } catch (\InvalidArgumentException $e) { } } $compile_class_name = ucfirst($this->camelize($this->name)); $this->_compile_class_name = 'Symforce\\AdminCache\\' . $compile_class_name . '\\Admin' . $compile_class_name; if (null === $this->tr_domain) { $this->tr_domain = $this->bundle_name; } $this->sf_domain = $gen->getSymforceDomain(); if (isset($cache->class_annotations[self::ANNOT_TREE_CLASS])) { // not work for yml/xml, because the private stof_doctrine_extensions.listener.tree service $tree_annot_len = strlen(self::ANNOT_TREE_CLASS); $this->tree = array(); foreach ($cache->propertie_annotations as $property_name => $as) { foreach ($as as $annot_class => &$value) { if (0 === strpos($annot_class, self::ANNOT_TREE_CLASS)) { $tree_config_key = strtolower(substr($annot_class, $tree_annot_len)); $this->tree[$tree_config_key] = $property_name; } } } if (!isset($this->tree['parent'])) { $this->throwError("missing @%sParent", self::ANNOT_TREE_CLASS); } if (!isset($this->tree['root'])) { $this->throwError("missing @%sRoot", self::ANNOT_TREE_CLASS); } } if (isset($cache->class_annotations[self::ANNOT_TOSTR_CLASS])) { \Dev::dump($cache->class_annotations[self::ANNOT_TOSTR_CLASS]); exit; } if (isset($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS])) { \Dev::dump($cache->class_annotations[self::ANNOT_TREE_LEAF_CLASS]); exit; } foreach ($cache->propertie_annotations as $property_name => $as) { if (isset($as[self::ANNOT_SLUG_CLASS])) { if ($this->property_slug_name) { $this->throwError("slug property duplicate(%s, %s)", $this->property_slug_name, $property_name); } $this->property_slug_name = $property_name; $this->property_slug_unique = $meta->isUniqueField($property_name); $this->property_slug_nullable = $meta->isNullable($property_name); } if (isset($as[self::ANNOT_TOSTR_CLASS])) { if ($this->property_value_name) { $this->throwError("@ToString(%s) is conflict with @ToString(%s)", $property_name, $this->property_value_name); } $this->property_value_name = $property_name; } if (isset($as[self::ANNOT_TREE_LEAF_CLASS])) { if (!$this->tree) { $this->throwError("use @%s(%s) without @%s", self::ANNOT_TREE_LEAF_CLASS, $property_name, self::ANNOT_TREE_CLASS); } if (isset($this->tree['leaf'])) { $this->throwError("@ToString(%s) is conflict with %s", self::ANNOT_TREE_LEAF_CLASS, $property_name, $this->tree['leaf']); } $this->tree['leaf'] = $property_name; } if (isset($as[Page::PAGE_ANNOT_CLASS])) { if ($this->page) { $this->throwError("page property duplicate(%s, %s)", $this->page->pege_property, $property_name); } $this->page = new Page($this, $property_name, $as[Page::PAGE_ANNOT_CLASS]); } if (isset($as[Owner::OWNER_ANNOT_CLASS])) { if ($this->owner) { $this->throwError("owner property duplicate(%s, %s)", $this->owner->owner_property, $property_name); } $this->owner = new Owner($this, $property_name, $as[Owner::OWNER_ANNOT_CLASS]); } } if (isset($cache->class_annotations[self::ANNOT_WORKFLOW_CLASS])) { $this->workflow = new Workflow($this, $cache->class_annotations[self::ANNOT_WORKFLOW_CLASS]); } if (!$this->form) { $this->form = new Form($this); } $this->form->bootstrap(); $this->action_collection = new ActionCollection($this); $this->_route_assoc = new RouteAssoc($this); if (null !== $this->position) { if ($this->dashboard && null === $this->dashboard->position) { $this->dashboard->position = $this->position; } if ($this->menu && null === $this->menu->position) { $this->menu->position = $this->position; } } }
/** * @Route("/upload/{type}/{uuid}.{ext}", name="sf_upload_cache", requirements={"type" = "html|file", "uuid" = "[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}", "ext" = "\w{2,5}" } ) * @Template() */ public function fileViewAction(Request $request, $type, $uuid, $ext) { $repo = $this->container->get('doctrine')->getManager()->getRepository('Symforce\\AdminBundle\\Entity\\File'); $file = $repo->loadByUUID($uuid); $is_debug = $this->container->getParameter('kernel.debug'); if ($file && $file->getSessionId() && $this->getRequest()->getSession()->getId() !== $file->getSessionId()) { if ($is_debug) { \Dev::dump($file); } return new Response('Not Found', 404, array('Content-Type' => 'text/plain')); } if (!$file) { return new Response('Not Found', 404, array('Content-Type' => 'text/plain')); } if ($ext !== $file->getExt()) { if ($is_debug) { \Dev::dump($file); } return new Response('Not Found', 404, array('Content-Type' => 'text/plain')); } $is_html_file = 'html' === $type; if ($is_html_file !== $file->getIsHtmlFile()) { if ($is_debug) { \Dev::dump($file); } return new Response('Not Found', 404, array('Content-Type' => 'text/plain')); } $response = new Response(); $response->setPrivate(); $response->setMaxAge(600); $response->setSharedMaxAge(600); // set a custom Cache-Control directive $response->headers->addCacheControlDirective('must-revalidate', true); $date = $file->getUpdated(); $response->setETag($date->getTimestamp()); $response->setLastModified($date); if ($response->isNotModified($request)) { return $response; } $response->headers->set('Content-Type', $file->getType()); $response->setContent(stream_get_contents($file->getContent())); return $response; }
public function getFormOptions() { $admin = $this->admin_object->getCompileClass(); $choices = $this->getChoices(); if ($choices) { $tr_path_map = array(); foreach ($choices as $option) { $this->fixOption($option); $tr_path_map[$option->value] = array($option->getLabel()->getPath(), $option->getLabel()->getDomain() !== $this->admin_object->tr_domain); } $admin->addLazyArray('form_choices', $this->class_property, $tr_path_map); } $options = parent::getFormOptions(); if (null !== $this->choice_code) { if ($this->choices) { $this->throwError(' can not use choices_code with choices'); } if (false == strpos($this->choice_code, '$')) { $options['choices'] = $this->compilePhpCode(sprintf('$this->%s($object)', $this->choice_code)); } else { $options['choices'] = $this->compilePhpCode($this->choice_code); } } else { $choices = $this->getChoices(); if (null !== $choices) { $choice_options = array(); foreach ($choices as $option) { if (!is_object($option)) { \Dev::dump($option); exit; } $this->fixOption($option); $choice_options[$option->value] = $option->getLabel()->getPhpCode(); } $options['choices'] = $choice_options; } } if ($this->expanded) { $options['expanded'] = true; } if ($this->multiple) { $options['multiple'] = true; } if ($this->virtual) { $options['virtual'] = true; } if (null === $this->empty_value) { if ($this->isNullable()) { // for select, this allow empty value if (!$this->expanded && !$this->multiple) { $options['empty_value'] = null; $options['empty_data'] = ''; } } else { $this->required = true; } } if ($this->empty_value) { $options['empty_value'] = $this->empty_value; $options['empty_data'] = $this->empty_data; $options['required'] = false; $this->required = false; } if (null !== $this->preferred_choices) { if (!$this->expanded) { throw new \Exception("preferred_choices need expanded=true"); } $options['preferred_choices'] = is_array($this->preferred_choices) ? $this->preferred_choices : array($this->preferred_choices); } return $options; }
protected function execute(InputInterface $input, OutputInterface $output) { $compiler = $this->getContainer()->get('sf.compiler.assets'); \Dev::dump($compiler); }
private function parseChildrenPermertions() { $children_config = array(); $self_config = array(); foreach ($this->children as $status_name => $status_config) { if ($status_config->target) { if (in_array('removed', $status_config->target)) { if (!isset($self_config['delete'])) { $self_config['delete'] = array(); } $self_config['delete'][$status_name] = true; } } if ($status_config->source) { if (in_array('none', $status_config->source)) { if (!isset($self_config['create'])) { $self_config['create'] = array(); } $self_config['create'][$status_name] = true; } } } $children_config[$this->admin_object->name] = $self_config; if ($this->_admin_children_permertions) { foreach ($this->_admin_children_permertions as $child_admin_name => $actions) { $visted = array(); $config = array('*' => array()); if ($child_admin_name !== $this->admin_object->name) { if (!$this->admin_object->generator->hasAdminName($child_admin_name)) { throw new \Exception(sprintf("admin(%s) workflow.children admin(%s) not exists", $this->admin_object->name, $child_admin_name)); } if (!$this->admin_object->_route_assoc->hasChildAdmin($child_admin_name, $visted)) { throw new \Exception(sprintf("admin(%s) has no child admin(%s)", $this->admin_object->name, $child_admin_name)); } } foreach ($actions as $action_name => $status_config) { if ($action_name !== '*') { if (!isset($this->admin_object->action_collection->children[$action_name])) { throw new \Exception(sprintf("admin(%s) workflow.children admin(%s) action(%s) not exists!", $this->admin_object->name, $child_admin_name, $action_name)); } } $_status_config = preg_split('/\\s*,\\s*/', trim($status_config)); $_valid_status = array(); foreach ($_status_config as $_status) { if (empty($_status)) { continue; } $flag_value = true; if (preg_match('/^[^\\w\\*\\_\\-]/', $_status, $_flag)) { $_flag = $_flag[0]; if ('@' === $_flag) { $flag_value = false; } else { if ('!' === $_flag) { $flag_value = -1; } else { $this->throwError("unknow flag(%s) for admin(%s) workflow.children admin(%s) action(%s)", $_flag, $this->admin_object->name, $child_admin_name, $action_name); } } $_status = trim(substr($_status, 1)); } if (empty($_status)) { throw new \Exception(sprintf("admin(%s) workflow.children admin(%s) action(%s) use empty status() !", $this->admin_object->name, $child_admin_name, $action_name)); } if ('*' !== $_status) { if (!isset($this->children[$_status])) { throw new \Exception(sprintf("admin(%s) workflow.children admin(%s) action(%s) use not exists status(%s) !", $this->admin_object->name, $child_admin_name, $action_name, $_status)); } } if (isset($_valid_status[$_status])) { throw new \Exception(sprintf("admin(%s) workflow.children admin(%s) action(%s) duplicate status(%s) !", $this->admin_object->name, $child_admin_name, $action_name, $_status)); } $_valid_status[$_status] = $flag_value; } $config[$action_name] = $_valid_status; } $default_config = $config['*']; if (isset($config['*']['*'])) { foreach ($this->children as $name => $none) { if (!isset($default_config[$name])) { $default_config[$name] = $config['*']['*']; } } unset($default_config['*']); } unset($config['*']); foreach ($config as $_aciton_name => &$_action_config) { if (isset($_action_config['*'])) { foreach ($default_config as $status => $status_value) { if (!isset($_action_config[$status])) { $_action_config[$status] = $status_value; } } unset($_action_config['*']); } } foreach ($this->admin_object->action_collection->children as $action_name => $none) { if (!isset($config[$action_name])) { $config[$action_name] = $default_config; } } foreach ($config as $action_name => &$action_config) { foreach ($action_config as $status => $none) { if (-1 === $none) { unset($action_config[$status]); } } } if ($child_admin_name === $this->admin_object->name) { /** * @todo no need config for myself ? */ \Dev::dump($config); exit; } $children_config[$child_admin_name] = $config; } } return $children_config; }