public function set_lazy_block(array &$context, \Twig_Template $tpl, $name, $key) { if (empty($key) || !is_string($key)) { throw new \Exception(sprintf("key(%s) must be string", json_encode($key))); } \Dev::shareCacheValue($key, function ($app) use(&$context, &$tpl, $name) { $tpl->displayBlock($name, $context); }); }
public function checkMethod(\ReflectionMethod $method) { $class = $method->getDeclaringClass(); if (!$class->isSubclassOf(self::BASE_CLASS_NAME)) { throw new \Exception(sprintf("%s with @(%s) must extends from class(%s)", \Dev::getMethodDeclaring($method), __CLASS__, self::BASE_CLASS_NAME)); } if ($method->isPrivate() || $method->isPublic()) { throw new \Exception(sprintf("%s with @(%s) must be protected", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isStatic()) { throw new \Exception(sprintf("%s with @(%s) can not be static", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isAbstract()) { throw new \Exception(sprintf("%s with @(%s) can not be abstract", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isConstructor()) { throw new \Exception(sprintf("%s with @(%s) can not be constructor", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isDestructor()) { throw new \Exception(sprintf("%s with @(%s) can not be destructor", \Dev::getMethodDeclaring($method), __CLASS__)); } $ps = $method->getParameters(); if (count($ps) !== 0) { throw new \Exception(sprintf("%s with @(%s) can not has parameters", \Dev::getMethodDeclaring($method), __CLASS__)); } }
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 handle(GetResponseEvent $event) { $sess = \Dev::getDiscuzSession(); if (!isset($sess->var['groupid']) && !$sess->var['groupid']) { return; } $token = new UserToken(); $token->setUserId($sess->var['uid']); try { $authToken = $this->authenticationManager->authenticate($token); $this->securityContext->setToken($authToken); return; } catch (AuthenticationException $failed) { // ... you might log something here // To deny the authentication clear the token. This will redirect to the login page. // Make sure to only clear your token, not those of other authentication listeners. // $token = $this->securityContext->getToken(); // if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) { // $this->securityContext->setToken(null); // } // return; throw $failed; } // By default deny authorization $response = new Response(); $response->setStatusCode(Response::HTTP_FORBIDDEN); $event->setResponse($response); }
public function __construct(\Symforce\DiscuzBundle\Annotation\Embed $config, \ReflectionMethod $method, \Symforce\DiscuzBundle\Service\PluginModule $pm) { $this->config = $config; $this->method = $method; $this->plugin_module = $pm; $this->code = \Dev::getMethodParametersDeclaringCode($method); }
public function getNewsList($tag, $limit = 9) { $repo = $this->getRepository(); $news_type = $repo->findOneBy(array('slug' => $tag)); $news_type_id = 0; $top_id = 0; if ($news_type) { $news_type_id = $this->getId($news_type); if ($news_type->top) { $top_id = $news_type->top->getId(); } } if ($news_type_id) { $dql = sprintf("SELECT a FROM AppWebBundle:news a WHERE a.news_type=%s AND a.id!=%d ORDER BY a.always_top DESC, a.created DESC", $news_type_id, $top_id); } else { $dql = sprintf("SELECT a FROM AppWebBundle:news a WHERE a.id!=%d ORDER BY a.always_top DESC, a.created DESC", $top_id); } $em = $this->getManager(); $query = $em->createQuery($dql); $query->setMaxResults($limit); $list = $query->getResult(); if ($top_id) { array_unshift($list, $news_type->top); } if (!$news_type) { $news_type = new \Symforce\PageBundle\Entity\NewsType(); $news_type->name = $tag; $this->getReflectionProperty('id')->setValue($news_type, $tag); } else { if (!$news_type instanceof $this->class_name) { throw new \Exception(sprintf("expect class `%s`, get `%s`", $this->class_name, \Dev::type($news_type))); } } return array($news_type, $list); }
/** * @return Dev */ public static function getInstance() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
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; }
/** * @param string $id * @return \Symforce\DiscuzBundle\Entity\User */ public function loadUserById($id) { /** * @var $em \Doctrine\ORM\EntityManager */ $em = \Dev::getContainer()->get('doctrine')->getManager(); $user = $em->getRepository('Symforce\\DiscuzBundle\\Entity\\User')->findOneBy(array('uid' => $id)); return $user; }
public static function runApplication($env, $debug) { if (self::$_container) { throw new \Exception(); } $kernel = new AppKernel($env, $debug); $kernel->loadClassCache(); $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); \Dev::Bootstrap($kernel, $request); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); }
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 checkMethod(\ReflectionMethod $method) { if ($method->isPrivate() || $method->isProtected()) { throw new \Exception(sprintf("%s with @(%s) must be public", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isStatic()) { throw new \Exception(sprintf("%s with @(%s) can not be static", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isAbstract()) { throw new \Exception(sprintf("%s with @(%s) can not be abstract", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isConstructor()) { throw new \Exception(sprintf("%s with @(%s) can not be constructor", \Dev::getMethodDeclaring($method), __CLASS__)); } if ($method->isDestructor()) { throw new \Exception(sprintf("%s with @(%s) can not be destructor", \Dev::getMethodDeclaring($method), __CLASS__)); } $class = $method->getDeclaringClass(); if (!$class->isSubclassOf(self::BASE_CLASS_NAME)) { throw new \Exception(sprintf("%s with @(%s) must extends from class(%s)", \Dev::getMethodDeclaring($method), __CLASS__, self::BASE_CLASS_NAME)); } $parent = $class->getParentClass(); $fn = $method->getName(); if ($parent->hasMethod($fn)) { throw new \Exception(sprintf("%s with @(%s) can not use with parent class method(%s)", \Dev::getMethodDeclaring($method), __CLASS__, $fn)); } if ($this->method) { if (!preg_match('/^[a-z][\\w\\_]+$/', $this->method)) { throw new \Exception(sprintf("%s with @(%s) method(%s) invalid", \Dev::getMethodDeclaring($method), __CLASS__, $this->method)); } } else { $this->method = $fn; } if (!$this->type) { $this->type = 'common'; } $exists = array('common' => array('spacecp_credit_extra', 'faq_extra', 'global_footer', 'global_footerlink', 'global_cpnav_top', 'global_cpnav_extra1', 'global_cpnav_extra2', 'global_usernav_extra1', 'global_usernav_extra2', 'global_usernav_extra3', 'global_usernav_extra4', 'global_nav_extra', 'global_header', 'global_userabout_top', 'userapp_menu_top', 'userapp_menu_middle', 'global_userabout_bottom'), 'forum' => array('collection_index_top', 'collection_index_bottom', 'collection_nav_extra', 'collection_index_top', 'collection_index_bottom', 'collection_index_top', 'collection_index_bottom', 'collection_nav_extra', 'collection_viewoptions', 'collection_view_top', 'collection_threadlistbottom', 'collection_relatedop', 'collection_view_bottom', 'collection_side_bottom', 'index_status_extra', 'index_nav_extra', 'index_top', 'index_catlist_top', 'index_favforum_extra', 'index_catlist', 'index_forum_extra', 'index_forum_extra', 'index_middle', 'index_bottom', 'index_side_top', 'index_side_bottom', 'viewthread_attach_extra', 'post_image_btn_extra', 'post_image_tab_extra', 'post_attach_btn_extra', 'post_attach_tab_extra', 'forumdisplay_leftside_top', 'forumdisplay_leftside_bottom', 'forumdisplay_forumaction', 'forumdisplay_modlink', 'forumdisplay_top', 'forumdisplay_middle', 'forumdisplay_postbutton_top', 'forumdisplay_threadtype_inner', 'forumdisplay_filter_extra', 'forumdisplay_threadtype_extra', 'forumdisplay_bottom', 'forumdisplay_side_top', 'forumdisplay_side_bottom', 'forumdisplay_fastpost_content', 'forumdisplay_fastpost_func_extra', 'forumdisplay_fastpost_ctrl_extra', 'global_login_text', 'forumdisplay_fastpost_btn_extra', 'forumdisplay_fastpost_sync_method', 'forumdisplay_filter_extra', 'forumdisplay_thread', 'forumdisplay_thread_subject', 'forumdisplay_author', 'forumdisplay_thread', 'forumdisplay_author', 'forumdisplay_threadlist_bottom', 'forumdisplay_postbutton_bottom', 'forumdisplay_postbutton_bottom', 'forumdisplay_subforum_extra', 'forumdisplay_subforum_extra', 'guide_nav_extra', 'guide_top', 'guide_bottom', 'forumdisplay_thread', 'index_navbar', 'post_top', 'post_middle', 'post_btn_extra', 'post_sync_method', 'post_bottom', 'post_activity_extra', 'post_debate_extra', 'post_editorctrl_right', 'post_editorctrl_left', 'post_editorctrl_top', 'post_editorctrl_bottom', 'post_side_top', 'post_side_bottom', 'post_infloat_top', 'post_infloat_middle', 'post_infloat_btn_extra', 'post_poll_extra', 'post_reward_extra', 'post_trade_extra', 'forumdisplay_modlayer', 'modcp_modlayer', 'viewthread_tradeinfo_extra', 'viewthread_top', 'viewthread_postbutton_top', 'viewthread_modoption', 'viewthread_beginline', 'viewthread_title_extra', 'viewthread_title_row', 'viewthread_middle', 'viewthread_bottom', 'viewthread_activity_extra1', 'viewthread_activity_extra2', 'viewthread_fastpost_side', 'viewthread_fastpost_content', 'viewthread_fastpost_func_extra', 'viewthread_fastpost_ctrl_extra', 'global_login_text', 'viewthread_fastpost_btn_extra', 'viewthread_postheader', 'viewthread_postheader', 'viewthread_postheader', 'viewthread_endline', 'viewthread_profileside', 'viewthread_imicons', 'viewthread_magic_user', 'viewthread_avatar', 'viewthread_sidetop', 'viewthread_sidebottom', 'viewthread_postheader', 'viewthread_modaction', 'viewthread_share_method', 'viewthread_useraction', 'viewthread_postsightmlafter', 'viewthread_postfooter', 'viewthread_postaction', 'viewthread_magic_thread', 'viewthread_magic_post', 'viewthread_endline', 'viewthread_posttop', 'global_login_text', 'viewthread_postbottom', 'viewthread_poll_top', 'viewthread_poll_bottom', 'viewthread_useraction_prefix', 'viewthread_useraction', 'viewthread_side_bottom', 'viewthread_trade_extra'), 'group' => array('group_navlink', 'forumdisplay_navlink', 'group_navlink', 'forumdisplay_navlink', 'group_top', 'forumdisplay_top', 'group_nav_extra', 'forumdisplay_nav_extra', 'group_bottom', 'forumdisplay_bottom', 'group_side_bottom', 'forumdisplay_side_bottom', 'forumdisplay_postbutton_top', 'forumdisplay_filter_extra', 'forumdisplay_thread', 'forumdisplay_postbutton_bottom', 'my_header', 'my_bottom', 'my_side_top', 'my_side_bottom', 'group_index_side', 'group_side_top', 'forumdisplay_side_top', 'index_header', 'index_top', 'index_bottom', 'index_side_top', 'index_side_bottom', 'index_top', 'index_grouplist', 'index_bottom', 'index_side_top', 'index_side_bottom'), 'home' => array('follow_nav_extra', 'follow_top', 'spacecp_avatar_top', 'spacecp_avatar_bottom', 'spacecp_blog_top', 'spacecp_blog_middle', 'spacecp_blog_bottom', 'spacecp_credit_top', 'spacecp_credit_extra', 'spacecp_credit_bottom', 'spacecp_credit_top', 'spacecp_credit_bottom', 'spacecp_privacy_top', 'spacecp_privacy_base_extra', 'spacecp_privacy_feed_extra', 'spacecp_privacy_bottom', 'spacecp_profile_top', 'spacecp_profile_extra', 'spacecp_profile_bottom', 'spacecp_promotion_top', 'spacecp_promotion_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'spacecp_usergroup_top', 'spacecp_usergroup_bottom', 'space_album_pic_top', 'space_album_pic_op_extra', 'space_album_pic_bottom', 'space_album_pic_face_extra', 'space_album_op_extra', 'space_blog_list_status', 'space_blog_title', 'space_blog_share_method', 'space_blog_op_extra', 'space_blog_face_extra', 'space_card_top', 'space_card_baseinfo_middle', 'space_card_baseinfo_bottom', 'space_card_option', 'space_card_magic_user', 'space_card_bottom', 'space_blog_comment_op', 'space_blog_comment_bottom', 'space_doing_top', 'space_doing_bottom', 'space_favorite_nav_extra', 'space_interaction_extra', 'global_usernav_extra1', 'global_usernav_extra2', 'space_home_side_top', 'space_home_side_bottom', 'space_home_top', 'space_home_navlink', 'space_home_bottom', 'magic_nav_extra', 'medal_nav_extra', 'space_menu_extra', 'space_profile_baseinfo_top', 'follow_profile_baseinfo_top', 'space_profile_baseinfo_middle', 'follow_profile_baseinfo_middle', 'space_profile_baseinfo_bottom', 'follow_profile_baseinfo_bottom', 'space_profile_extrainfo', 'follow_profile_extrainfo', 'space_share_comment_op', 'space_home_doing_sync_method', 'space_wall_face_extra'), 'member' => array('logging_side_top', 'logging_top', 'logging_input', 'logging_method', 'global_login_extra', 'register_side_top', 'register_top', 'register_input', 'register_logging_method', 'register_bottom'), 'portal' => array('portalcp_top', 'portalcp_extend', 'portalcp_middle', 'portalcp_bottom', 'view_article_top', 'view_article_subtitle', 'view_article_summary', 'view_article_content', 'view_share_method', 'view_article_op_extra', 'view_article_side_top', 'view_article_side_bottom'), 'ranklist' => array('ranklist_nav_extra'), 'search' => array('album_top', 'album_bottom', 'blog_top', 'blog_bottom', 'global_footer', 'global_footerlink', 'forum_top', 'forum_bottom', 'group_top', 'group_bottom', 'global_usernav_extra1', 'global_usernav_extra2', 'portal_top', 'portal_bottom'), 'userapp' => array('userapp_app_top', 'userapp_app_bottom', 'userapp_index_top', 'userapp_index_bottom', 'userapp_menu_top', 'userapp_menu_middle', 'userapp_menu_bottom'), 'mobile_common' => array('global_footer_mobile', 'global_header_mobile'), 'mobile_forum' => array('index_top_mobile', 'index_middle_mobile', 'index_bottom_mobile', 'forumdisplay_top_mobile', 'forumdisplay_thread_mobile', 'forumdisplay_bottom_mobile', 'viewthread_top_mobile', 'viewthread_posttop_mobile', 'viewthread_postbottom_mobile', 'viewthread_bottom_mobile')); if (!isset($exists[$this->type])) { throw new \Exception(sprintf("%s with @(%s) type(%s) must be one of(%s)", \Dev::getMethodDeclaring($method), __CLASS__, json_encode($this->type), join(', ', array_keys($exists)))); } }
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; }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $bbs_parameters_file = $this->getContainer()->getParameter('kernel.root_dir') . '/config/parameters_bbs.yml'; if (!file_exists($bbs_parameters_file)) { $parameters = array('parameters' => array()); $output->writeln("generate parameters from discuz config files"); $root_dir = $this->getContainer()->getParameter('sf.web_root_dir'); $file = sprintf('%s/config/config_global.php', $root_dir); include $file; $parameters['parameters']['sf.bbs.memory_prefix'] = $_config['memory']['prefix']; $parameters['parameters']['sf.bbs.cookiepre'] = $_config['cookie']['cookiepre']; $parameters['parameters']['sf.bbs.security_authkey'] = $_config['security']['authkey']; $parameters['parameters']['sf.bbs.remote_appkey'] = $_config['remote']['appkey']; $file = sprintf('%s/config/config_ucenter.php', $root_dir); $const = $this->getDefineConst($file); $parameters['parameters']['sf.bbs.uc_key'] = $const['UC_KEY']; $file = sprintf('%s/uc_server/data/config.inc.php', $root_dir); $const = $this->getDefineConst($file); $parameters['parameters']['sf.bbs.ucs_found_pw'] = $const['UC_FOUNDERPW']; $parameters['parameters']['sf.bbs.ucs_found_salt'] = $const['UC_FOUNDERSALT']; $parameters['parameters']['sf.bbs.ucs_key'] = $const['UC_KEY']; $parameters['parameters']['sf.bbs.ucs_site_id'] = $const['UC_SITEID']; $parameters['parameters']['sf.bbs.ucs_mykey'] = $const['UC_MYKEY']; $data = \Symfony\Component\Yaml\Yaml::dump($parameters); \Dev::write_file($bbs_parameters_file, $data); } else { $output->writeln(sprintf("generate parameters from %s", $bbs_parameters_file)); $parameters = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($bbs_parameters_file)); } $parameters_file = $this->getContainer()->getParameter('kernel.root_dir') . '/config/parameters.yml'; $_parameters = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($parameters_file)); foreach ($parameters['parameters'] as $key => $value) { $_parameters['parameters'][$key] = $value; } $_data = \Symfony\Component\Yaml\Yaml::dump($_parameters); \Dev::write_file($parameters_file, $_data); }
/** * @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; }
/** * Saves a file from a url. * * @param string $url The full url for the file to save. * @param string $type The file type to store in the db (file, image, video) * * @return Returns the media id if created successfully, boolean false otherwise. */ public static function saveFromUrl($url, $type) { if (!($nameAndPath = self::_getNewNameAndPath(basename($url)))) { return false; } list($newFilename, $fullPath) = $nameAndPath; if ($urlContent = file_get_contents($url)) { if (file_put_contents($fullPath, $urlContent)) { $id = Media::m('file')->insert(array('name' => $newFilename, 'path' => Media::getMediaPath(), 'size' => filesize($fullPath), 'mime_type' => self::_determineMimeType($fullPath), 'file_type' => $type)); return $id; } else { self::$_error = 'Unable to save ' . $type . ' from URL.'; } } else { self::$_error = 'Unable to read file contents from URL.'; Dev::debug('media', 'ERROR: Cant save from url: ' . $url); } return false; }
//подключаем diafan define('DIAFAN', 1); define('TITLE', "Регистрация на сайте"); define('_LANG', 1); define('IS_ADMIN', 0); define('REVATIVE_PATH', ''); define('BASE_PATH', "http" . (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? "s" : '') . "://" . getenv("HTTP_HOST") . "/" . (REVATIVE_PATH ? REVATIVE_PATH . '/' : '')); define('ABSOLUTE_PATH', dirname(__FILE__) . '/../'); define('BASE_PATH_HREF', BASE_PATH . "registration/"); //define('BASE_URL', ($domain ? $domain : getenv("HTTP_HOST")).(REVATIVE_PATH ? '/'.REVATIVE_PATH : '')); define('BASE_URL', getenv("HTTP_HOST") . (REVATIVE_PATH ? '/' . REVATIVE_PATH : '')); include_once ABSOLUTE_PATH . 'includes/custom.php'; include_once ABSOLUTE_PATH . 'includes/developer.php'; include_once ABSOLUTE_PATH . 'includes/diafan.php'; include_once ABSOLUTE_PATH . 'includes/file.php'; Dev::init(); include_once ABSOLUTE_PATH . 'config.php'; include_once ABSOLUTE_PATH . 'includes/core.php'; include_once ABSOLUTE_PATH . 'includes/init.php'; $diafan = new Init(); Custom::inc('includes/controller.php'); Custom::inc('includes/model.php'); Custom::inc('includes/action.php'); Custom::inc('includes/controller.php'); Custom::inc('includes/model.php'); Custom::inc('includes/action.php'); $receiver = new PayqrReceiver(); $receiver->handle($diafan); } catch (PayqrExeption $e) { PayqrLog::log($e->response); }
public function compileValue() { if (null !== $this->_compile_value) { return $this->_compile_value; } $r = $this->admin_object->reflection->getProperty($this->class_property); $property_name = $this->class_property; $property_code = '_property_value'; if ($this->template) { try { $this->admin_object->generator->loadTwigTemplatePath($this->template); } catch (\InvalidArgumentException $e) { throw $e; $this->setChainException($e); $this->throwError(" %s->%s use template:`%s` not found", $this->admin_name, $this->class_property, $this->template); } $code = '{% include "' . $this->template . '" with { admin: admin, action: action, property:' . json_encode($this->class_property) . ', object: _object, value:attribute(_object, "' . $this->class_property . '") } %}'; } else { if ($this->code) { $code = $this->code; } else { if ($this->admin_object->workflow && $this->class_property === $this->admin_object->workflow->property) { $code = '{{ admin.getObjectWorkflowLabel(_object) }}'; } else { if ($this->admin_object->owner && $this->class_property === $this->admin_object->owner->owner_property) { // $code = '{{ admin.owneradmin.string( attribute(_object, "' . $this->class_property . '") ) }}' ; $map = $this->getPropertyDoctrineAssociationMapping(); $code = $this->getMapValueCode($property_code, $map); } else { $code = '{{ ' . $property_code . ' }}'; if ($this->form_element) { if ($this->form_element instanceof Form\Integer) { if ($this->form_element instanceof Form\Range) { $code = $property_code; if (null !== $this->form_element->precision) { $code .= sprintf('|number_format(%d, ".", ",")', $this->form_element->precision); } $code = '<span class="number">{{ ' . $code . ' }}</span>'; if (null !== $this->form_element->_unit) { $code .= $this->form_element->_unit->getTwigCode(); } } else { if ($this->form_element instanceof Form\Money) { $code = '{{ ' . sprintf('sf_money(%s, %d, "%s")', $property_code, $this->form_element->precision, $this->form_element->currency) . ' }}'; } else { if ($this->form_element instanceof Form\Percent) { $code = '{{ ' . sprintf('%s|number_format(%d, ".", ",")', $property_code, $this->form_element->precision) . ' }}'; } else { $code = '{{ ' . sprintf('%s|number_format(0, ".", ",")', $property_code) . ' }}'; } } } } else { if ($this->form_element instanceof Form\Choice) { $code = '{{ admin.getChoiceText("' . $this->class_property . '", _object) }}'; if ($this->form_element instanceof Form\Owner) { $code = '{{ ' . $property_code . ' }}'; } else { if ($this->form_element instanceof Form\Entity) { $map = $this->getPropertyDoctrineAssociationMapping(); $code = $this->getMapValueCode($property_code, $map, $action = 'view'); } else { if ($this->form_element instanceof Form\Checkbox) { } else { if ($this->form_element instanceof Form\Radio) { } else { if ($this->form_element instanceof Form\Bool) { } else { if ($this->form_element instanceof Form\Country) { } else { if ($this->form_element->multiple) { $code = '{{ admin.getChoicesText("' . $this->class_property . '", _object) }}'; } } } } } } } } else { if ($this->form_element instanceof Form\DateTime) { $format = $this->format ?: $this->form_element->format; $code = '{{ sf_date_format(' . $property_code . ', "' . $format . '" ) }}'; if ($this->form_element instanceof Form\Birthday) { } } else { if ($this->form_element instanceof Form\File) { if ($this->form_element instanceof Form\Image) { // $this->form_element->image_size $code = '{% if ' . $property_code . ' %}' . sprintf('<div class="sf_image_view" style="width:%spx;height:%spx;"><img src="{{ web_assets_dir }}{{ %s }}" /></div>', $this->form_element->image_size[0], $this->form_element->image_size[1], $property_code) . '{% endif %}'; } else { $code = '{% if ' . $property_code . ' %}' . sprintf('<div class="sf_file_view"><a href="{{ web_assets_dir }}{{ %s }}" >{{ %s }}</a></div>', $property_code, $property_code) . '{% endif %}'; } } else { if ($this->form_element instanceof Form\Embed) { $map = $this->getPropertyDoctrineAssociationMapping(); $code = $this->getMapValueCode($property_code, $map); } else { if ($this->form_element instanceof Form\Text) { if ($this->form_element instanceof Form\Textarea) { if ($this->form_element instanceof Form\Html) { $code = '{{ ' . $property_code . ' | raw }}'; } else { if ($this->form_element instanceof Form\Markdown) { } } } else { if ($this->form_element instanceof Form\Color) { } else { if ($this->form_element instanceof Form\Url) { } else { if ($this->form_element instanceof Form\Email) { } else { if ($this->form_element instanceof Form\Password) { $code = '******'; } else { if ($this->admin_object->property_value_name === $this->class_property) { // add view to this action $url = '{{ admin.path("view", _object) }}'; $code = '{% if admin.auth("view", _object) %}'; $code .= sprintf('<a href="%s">{{ %s }}</a>', $url, $property_code); $code .= '{% else %}'; $code .= sprintf('{{ %s }}', $property_code); $code .= '{% endif %}'; } } } } } } } else { if ($this->form_element instanceof Form\Tree) { $map = $this->getPropertyDoctrineAssociationMapping(); $code = $this->getMapValueCode($property_code, $map); } else { if ($this->form_element instanceof \Symforce\UserBundle\Form\MetaType\AuthorizeMetaType) { $code = '*'; } else { \Dev::debug($this->admin_object->name, $this->class_property, get_class($this->form_element)); } } } } } } } } } else { // check form type /** * @var \Doctrine\ORM\Mapping\ClassMetadata */ $meta = $this->getEntityMetadata(); $map = $this->getPropertyDoctrineAssociationMapping(); if ($map) { $target_class = $map['targetEntity']; // to_one if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_ONE) { // find parent route $code = $this->getMapValueCode($property_code, $map); } else { if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) { // find child route $child_admin_object = $this->admin_object->generator->getAdminByClass($target_class); $url = sprintf('{{ admin.childpath(_object, "%s", "%s", "list", %s ) }}', $this->class_property, $child_admin_object->name, $property_code); $text = $child_admin_object->label->getTwigCode(); $code = '{% if ' . sprintf('sf_auth("%s", "list")', $child_admin_object->name) . ' %}'; $code .= sprintf('<a href="%s">%s ({{ %s.count() }})</a>', $url, $text, $property_code); $code .= '{% else %}'; $code .= sprintf('%s ({{ %s.count() }}) ', $text, $property_code); $code .= '{% endif %}'; } else { if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_ONE) { // find sibling entity $code = $this->getMapValueCode($property_code, $map); } else { throw new \Exception('bigger error'); } } } } else { $orm_type = $this->getPropertyDoctrineType(); if ($orm_type) { if ('date' === $orm_type) { $format = $this->format ?: "Y/m/d"; $code = '{{ sf_date_format(' . $property_code . ', "' . $format . '" ) }}'; } else { if ('datetime' === $orm_type) { $format = $this->format ?: "Y/m/d H:i:s"; $code = '{{ sf_date_format(' . $property_code . ', "' . $format . '" ) }}'; } else { if ('time' === $orm_type) { $format = $this->format ?: "H:i:s"; $code = '{{ sf_date_format(' . $property_code . ', "' . $format . '" ) }}'; } else { if ('integer' === $orm_type) { } else { if ('text' === $orm_type) { } else { if ('string' === $orm_type) { } else { if ('boolean' === $orm_type) { } else { if ('array' === $orm_type) { // list foreach array value ? } else { \Dev::debug($this->admin_object->name, $this->class_property, $orm_type); } } } } } } } } } else { // not sure what to do // \Dev::debug($this->admin_object->name, $this->class_property, $orm_type ); } } } if ($this->tag) { $code = $this->tag->compileTag($code); } if ($this->href) { // @TODO add link handle $code = $this->href->compileTag($code); } } } } } $this->_compile_value = $code; return $code; }
public final function addAction(\Symforce\DiscuzBundle\Annotation\Action $config, \ReflectionMethod $method) { if ($config->name) { if (!preg_match('/^[a-zAZ\\_][\\_\\w]*$/', $config->name)) { throw new \Exception(sprintf("%s with @(%s) name(%s) invlaid", \Dev::getMethodDeclaring($method), get_class($config), json_encode($config->name))); } } else { $config->name = strtolower(preg_replace('/^on|Action$/', '', $method->getName())); } if (isset($this->action_helpers[$config->name])) { throw new \Exception(sprintf("%s with @(%s) name(%s) duplicate with %s ", \Dev::getMethodDeclaring($method), get_class($config), json_encode($config->name), \Dev::getMethodDeclaring($this->action_helpers[$config->name]->method))); } $this->action_helpers[$config->name] = new ActionHelper($config, $method, $this); if ($config->default) { if ($this->action_default) { throw new \Exception(sprintf("%s with @(%s) default duplicate with %s ", \Dev::getMethodDeclaring($method), get_class($config), \Dev::getMethodDeclaring($this->config_methods[$this->action_default]->method))); } $this->action_default = $config->name; } }
public function addFormElement($builder, $property_name, array $_options = null, $type = null) { $options = $this->getFormBuilderOption($property_name); if (!$options) { throw new \Exception(sprintf("%s->%s not exists", $this->name, $property_name)); } if (null === $type) { $type = $options['sf_form_type']; } else { if ($type === 'sf_view') { $options = array('label' => $options['label']); } } $subscribers = null; if (isset($options['subscribers'])) { $subscribers = $options['subscribers']; unset($options['subscribers']); } $constraints = null; if (isset($options['constraints']) && isset($_options['constraints'])) { $constraints = array(); foreach ($options['constraints'] as $constraint) { $constraints[get_class($constraint)] = $constraint; } foreach ($_options['constraints'] as $constraint) { $constraints[get_class($constraint)] = $constraint; } unset($options['constraints']); unset($_options['constraints']); } if ($_options) { \Dev::merge($options, $_options); } if (isset($options['required']) && $options['required']) { $constraint = new \Symfony\Component\Validator\Constraints\NotBlank(); if (!$constraints) { $constraints = array(); } $constraints[get_class($constraint)] = $constraint; } if ($constraints) { $options['constraints'] = array_values($constraints); } $builder->add($property_name, $type, $options); if ($subscribers) { $_builder = $builder->get($property_name); foreach ($subscribers as $subscriber) { $events = $subscriber->getSubscribedEvents(); foreach ($events as $_event => $method) { $_builder->addEventListener($_event, array($subscriber, $method)); } } } }
public function writeCache() { static $_psr4_map = null; if (null === $_psr4_map) { $_psr4_file = dirname((new \ReflectionClass('Composer\\Autoload\\ClassLoader'))->getFileName()) . '/autoload_psr4.php'; if (!file_exists($_psr4_file)) { throw new \Exception(sprintf("psr4 file(%s) not exits!", $_psr4_file)); } $_psr4_map = (include $_psr4_file); } $_class_file = null; foreach ($_psr4_map as $_namespace => $_namespace_dir) { if (!empty($_namespace_dir)) { $_pos = strpos($this->getName(), $_namespace); if (0 === $_pos) { $_class_file = $_namespace_dir[0] . '/' . str_replace('\\', '/', substr($this->getName(), strlen($_namespace))) . '.php'; } } } if (!$_class_file) { throw new \Exception(sprintf("can not resolve file for class(%s) by psr4 rule!", $this->getName())); } $shortName = pathinfo($_class_file, \PATHINFO_FILENAME); $namespace = $this->getNamespace(); $writer = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter(); $writer->writeln("<?php\n"); if (!empty($namespace)) { $writer->writeln("namespace " . $namespace . ";\n"); } $imports = $this->getUseStatements(); foreach ($imports as $alias => $use) { $_alias = substr($use, -1 - strlen($alias)); if ($_alias == '\\' . $alias) { $writer->writeln(sprintf("use %s ;", $use)); } else { $writer->writeln(sprintf("use %s as %s ;", $use, $alias)); } } $writer->writeln('')->writeln('/**')->writeln(' * This code has been auto-generated by the SymforceAdminBundule')->writeln(' * Manual changes to it will be lost.')->writeln(' */'); if ($this->isAbstract()) { $writer->write('abstract '); } else { if ($this->isFinal()) { $writer->write('final '); } } $writer->write('class ' . $shortName); if ($this->getParentClassName()) { $writer->write(' extends ' . $this->getParentClassName()); } $writer->writeln(' {')->indent(); $lazy_writer = $this->getLazyWriter(); foreach ($this->getProperties() as $property) { $property->writeCache($lazy_writer, $writer); } foreach ($this->lazy_properties as $name => $value) { $writer->writeln("\npublic \${$name} = " . $this->propertyEncode($value) . " ;"); // $lazy_writer->writeln( '$this->' . $name . ' = ' . . ' ; ' ); } if ($this->hasMethod('__wakeup')) { $lazy_writer->writeln($this->getMethod('__wakeup')->getBody()); $this->getMethod('__wakeup')->setBody($lazy_writer->getContent()); } else { $this->setMethod(\CG\Generator\PhpMethod::create('__wakeup')->setFinal(true)->setVisibility('protected')->setBody($lazy_writer->getContent())); } foreach ($this->getMethods() as $method) { if ($method instanceof PhpMethod) { $method->flushLazyCode(); $_body = $method->getWriter()->getContent(); } else { $_body = $method->getBody(); } $writer->write("\n"); if ($method->getDocblock()) { $writer->writeln($method->getDocblock()); } if ($method->isFinal()) { $writer->write('final '); } $writer->write($method->getVisibility())->write(' function ')->write($method->getName()); $ps = $method->getParameters(); if (empty($ps)) { $writer->write('()'); } else { $writer->writeln('(')->indent(); foreach ($method->getParameters() as $i => $p) { if ($p->getType()) { if (in_array($p->getType(), array('mixed'))) { $writer->write('/** @var ' . $p->getType() . ' */'); } else { $writer->write($p->getType() . ' '); } } if ($p->isPassedByReference()) { $writer->write(' & '); } $writer->write(' $')->write($p->getName()); if ($p->hasDefaultValue()) { $writer->write(' = ' . json_encode($p->getDefaultValue())); } if ($i < count($ps) - 1) { $writer->writeln(","); } else { $writer->write("\n"); } } $writer->writeln(')')->outdent(); } $writer->writeln('{')->indent()->writeln($_body)->outdent()->writeln("}"); } $writer->outdent()->writeln('}'); $content = $writer->getContent(); /** * convert the fake php code * '#php{% $this->admin->trans("test.form.enabled.choices.no") %}' */ $content = preg_replace_callback(self::PHP_CODE, function ($m) { return stripslashes($m[1]); }, $content); $_class_dir = dirname($_class_file); if (!file_exists($_class_dir)) { if (!@mkdir($_class_dir, 0755)) { throw new \Exception(sprintf("mkdir(%s) error!", $_class_dir)); } } \Dev::write_file($_class_file, $content); return $_class_file; }
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; } } }
/** * @return \Symforce\AdminBundle\Compiler\Generator\PhpClass */ public function compile() { parent::compile(); // $this->children->properties $rc = $this->admin_object->reflection; $admin_class = $this->admin_object->getCompileClass(); $class = $this->getCompileClass(); $twig_writer = $this->_twig->getWriter(); // generate twig template $twig_writer->writeln('{% set _object = object %}')->writeln('{% block content_view %}')->writeln('<div class="form-horizontal">')->indent(); $children = array(); foreach ($this->admin_object->form->children->properties as $property_name => $_property) { if (isset($this->children->properties[$property_name])) { $property = $this->children->properties[$property_name]; $property->_annot = true; } else { $property = new ViewProperty($this->children, $this->admin_object, $property_name); $property->lazyInitialize(); $children[$property_name] = $property; } if (null !== $_property->group && null === $property->group) { $property->set_group($_property->group); } if (null !== $_property->position && null === $property->position) { $property->set_position($_property->position); } } foreach ($rc->getProperties() as $p) { if ($p->isStatic()) { continue; } $property_name = $p->getName(); if (isset($children[$property_name])) { continue; } if (isset($this->children->properties[$property_name])) { $property = $this->children->properties[$property_name]; } else { $property = new ViewProperty($this->children, $this->admin_object, $property_name); $property->lazyInitialize(); $property->_no_form_and_view = true; } $children[$property_name] = $property; } $macro_writer = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter(); foreach ($children as $property_name => $property) { $label = null; if ($property->form_element) { $label = $property->form_element->label; } else { if (isset($this->admin_object->action_collection->children['list']->children->properties[$property_name])) { $label = $this->admin_object->action_collection->children['list']->children->properties[$property_name]->label; } else { $label = $property->label; } } $admin_twig_calss = var_export($this->admin_object->class_name, 1); $admin_twig_code = sprintf('sf_admin_class(%s)', $admin_twig_calss); $admin_class->addLazyArray('properties_label', $property_name, array($label->getPath(), $label->getDomain())); $macro_writer->write('{% ' . sprintf('macro macro_label_%s(admin=false)', $property_name) . ' %}')->write('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}'); if ($this->admin_object->_final_template) { $macro_writer->write('{% ' . sprintf('import "%s" as parent_macro', $this->admin_object->_final_template) . ' %}')->write('{% ' . sprintf('if twig_macro_exists(parent_macro, "macro_label_%s") ', $property_name) . ' %}')->indent()->write('{{ ' . sprintf('parent_macro.macro_label_%s(admin)', $property_name) . '}}')->outdent()->write('{% else %}')->indent()->write('{{' . $property->compileLabel() . ' }}')->outdent()->write('{% endif %}'); } else { $macro_writer->write('{{ ' . $property->compileLabel() . ' }}'); } $macro_writer->writeln('{% endmacro %} '); $macro_writer->writeln('{% ' . sprintf('macro macro_value_%s(_object, _property_value=false, admin=false)', $property_name) . ' %}')->indent()->writeln('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}'); if ($this->admin_object->generator->getParameter('kernel.debug')) { $macro_writer->writeln(sprintf('{{ sf_check_class(_object, %s) }}', $admin_twig_calss)); } $macro_writer->writeln('{% if _property_value is same as(false) %}{% set _property_value = ' . $property->getTwigValue() . ' %}{% endif %}'); if ($this->admin_object->_final_template) { $macro_writer->writeln('{% ' . sprintf('import "%s" as parent_macro', $this->admin_object->_final_template) . ' %}')->writeln('{% ' . sprintf('if twig_macro_exists(parent_macro, "macro_value_%s") ', $property_name) . ' %}')->indent()->writeln('{{ ' . sprintf('parent_macro.macro_value_%s(_object, _property_value, admin)', $property_name) . '}}')->outdent()->writeln('{% else %}')->indent()->writeln($property->compileValue())->outdent()->writeln('{% endif %}'); } else { $macro_writer->writeln($property->compileValue()); } $macro_writer->outdent()->writeln('{% endmacro %} '); $macro_writer->write("\n"); } if ($this->admin_object->workflow) { $macro_writer->writeln('{% macro macro_workflow_report(admin=false) %}')->indent()->writeln('{% if admin is same as(false) %}{% set admin = ' . $admin_twig_code . ' %}{% endif %}'); $this->admin_object->workflow->compileListAction($macro_writer); $macro_writer->outdent()->writeln('{% endmacro %}'); } \Dev::write_file($this->admin_object->_template_path, $macro_writer->getContent()); if ($this->admin_object->form->groups) { foreach ($this->admin_object->form->groups as $_group) { $_annot = array('id' => $_group->id, 'label' => $_group->label); if ($_group->name) { $_annot['name'] = $_group->name; } if (null !== $_group->position) { $_annot['position'] = $_group->position; } $this->_groups[$_group->id] = new ActionPropertyGroup($_annot); } } if (!isset($this->_groups['default'])) { $this->_groups['default'] = new ActionPropertyGroup('default'); } foreach ($children as $property_name => $property) { if ($property->form_element && 'apppassword' === $property->form_element->compile_form_type) { continue; } if ($property->_no_form_and_view) { continue; } if ($property->group) { if (isset($this->_groups[$property->group])) { $group = $this->_groups[$property->group]; } else { $group = new ActionPropertyGroup($property->group); $this->_groups[$property->group] = $group; } } else { $group = $this->_groups['default']; } $group->add($property->class_property, $property->position); } foreach ($this->_groups as $group) { $group->fixLabel($this->admin_object->form->tr_node, $this->admin_object->generator->sf_domain); $group->sort(); } $_anonymous_children = array(); foreach ($this->admin_object->_route_assoc->_anonymous_children as $child_admin_name => $child_properties) { $child_admin = $this->admin_object->generator->getAdminByName($child_admin_name); if (!$child_admin->_final_template) { continue; } $_anonymous_children[$child_admin_name] = $child_properties; } if (count($this->_groups) > 1) { foreach ($this->_groups as $group) { if (!count($group->properties)) { continue; } $twig_writer->writeln('{% set view_property_count = 0 %}')->writeln('<fieldset class="view-group">')->indent(); foreach ($group->properties as $property_name) { $children[$property_name]->compileView($twig_writer); } $twig_writer->write('{% if view_property_count > 0 %}')->write('<legend class="view-group-header">')->write($group->label->getTwigCode())->write('</legend>')->writeln('{% endif %}')->outdent()->writeln('</fieldset>'); } if (!empty($_anonymous_children)) { $twig_writer->writeln('{% set view_property_count = 0 %}')->writeln('<fieldset class="view-group">')->indent(); $this->compileAnonymousChildren($_anonymous_children, $twig_writer); $twig_writer->write('{% if view_property_count > 0 %}')->write('<legend class="view-group-header">Others</legend>')->writeln('{% endif %}')->outdent()->writeln('</fieldset>'); } } else { foreach ($this->_groups as $group) { $twig_writer->writeln('{% set view_property_count = 0 %}'); foreach ($group->properties as $property_name) { $children[$property_name]->compileView($twig_writer); } } $this->compileAnonymousChildren($_anonymous_children, $twig_writer); } $twig_writer->writeln('{% block _admin_view_extra %}')->writeln('{% endblock %}')->outdent()->writeln('</div>')->writeln('{% endblock %}'); return $class; }
public function lazyInitialize() { if ($this->lazy_initialized) { throw new \Exception('big error'); } $this->lazy_initialized = true; // add tranlation $this->tr_node = $this->property_container->tr_node->getNodeByPath($this->class_property); if (!$this->label) { $map = $this->getPropertyDoctrineAssociationMapping(); if ($map && $this->admin_object->generator->hasAdminClass($map['targetEntity'])) { $admin = $this->admin_object->generator->getAdminByClass($map['targetEntity']); $this->label = $admin->getLabel(); } else { $this->label = $this->admin_object->generator->getTransValue('property', $this->class_property . '.label'); } } else { $this->label = $this->tr_node->createValue('label', $this->label); } if (null !== $this->show_on) { if (!is_array($this->show_on)) { $this->throwError("show_on need be array, you set %s", gettype($this->show_on)); } $_or = $this->show_on; if (!\Dev::isSimpleArray($this->show_on)) { $_or = array($_or); } foreach ($_or as $_or_i => $_and) { foreach ($_and as $_property => $values) { if (!$this->property_container->hasProperty($_property)) { $this->throwError("show_on use property `%s` not form type", $_property); } $element = $this->property_container->getProperty($_property); if (!$element instanceof Choice && !$element instanceof Workflow) { $this->throwError("show_on use property `%s` is (%s) form type, exprect choice type", $_property, $element->compile_form_type); } } } foreach ($_or as $and_i => $and) { foreach ($and as $when_i => $values) { if (!is_array($values)) { $values = explode(',', trim($values)); } foreach ($values as $_value_i => $when_value) { $values[$_value_i] = (string) trim($when_value); } $_or[$and_i][$when_i] = $values; } } $this->show_on = $_or; } if (null !== $this->parent_on) { $on = $this->parent_on; foreach ($on as $parent_property_name => $_or) { if (!\Dev::isSimpleArray($_or)) { $_or = array($_or); } if (!$this->property_container->entity->reflection->hasProperty($parent_property_name)) { $this->throwError("parent_on use property `%s` not exists", $parent_property_name); } if (!$this->property_container->entity->orm_metadata->hasAssociation($parent_property_name)) { $this->throwError("parent_on use property `%s` not orm association", $parent_property_name); } $map = $this->property_container->entity->getPropertyDoctrineAssociationMapping($parent_property_name); if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) { $this->throwError("parent_on use property `%s` with one to many orm map", $parent_property_name); } if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY) { $this->throwError("parent_on use property `%s` with many to many orm map", $parent_property_name); } $admin = $this->admin_object->generator->getAdminByClass($map['targetEntity']); foreach ($_or as $_or_i => $_and) { foreach ($_and as $_property => $values) { if (!$admin->reflection->hasProperty($_property)) { $this->throwError("parent_on use property `%s` not exists", $parent_property_name, $_property); } } } foreach ($_or as $and_i => $and) { foreach ($and as $when_i => $values) { if (!is_array($values)) { $values = explode(',', trim($values)); } foreach ($values as $_value_i => $when_value) { $values[$_value_i] = (string) trim($when_value); } $_or[$and_i][$when_i] = $values; } } $on[$parent_property_name] = $_or; } $this->parent_on = $on; } }
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 flush(\Symforce\AdminBundle\Compiler\Generator $gen) { $template_path = $gen->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template_file; \Dev::write_file($template_path, $this->writer->getContent()); }