読者です 読者をやめる 読者になる 読者になる

EC-CUBE3で頻繁に出てくる$appにセットされているもの

EC-CUBE3 PHP

EC-CUBE3ではSilexを利用しているため、お作法としてApplication.phpを起点に処理を行っています。

ではControllerで$appと頻繁に使われているこの変数(twigだとappのことです)には何がセットされているのかを見てみましょう。

表示の仕方は、3.0.8からの機能になりますがdumpという関数が使えるようになりますので、こちらを使って表示してみます。

  • Controllerでの使用方法
    dump($app)

  • Twigでの使用方法
    {{ dump(app) }}

Application {#8 ▼
  #providers: array:21 [▼
    0 => EccubeMonologServiceProvider {#34}
    1 => MonologServiceProvider {#35}
    2 => TranslationServiceProvider {#46}
    3 => SessionServiceProvider {#55 ▶}
    4 => TwigServiceProvider {#59}
    5 => HttpFragmentServiceProvider {#84}
    6 => UrlGeneratorServiceProvider {#99}
    7 => FormServiceProvider {#102}
    8 => SerializerServiceProvider {#119}
    9 => ValidatorServiceProvider {#126}
    10 => SwiftmailerServiceProvider {#140}
    11 => DoctrineServiceProvider {#155}
    12 => DoctrineOrmManagerRegistryProvider {#170}
    13 => DoctrineOrmServiceProvider {#194}
    14 => SecurityServiceProvider {#171 ▶}
    15 => RememberMeServiceProvider {#188}
    16 => EccubeServiceProvider {#259}
    17 => ServiceControllerServiceProvider {#585}
    18 => WebProfilerServiceProvider {#1068}
    19 => DebugServiceProvider {#1134}
    20 => SaxulumWebProfilerProvider {#1147}
  ]
  #booted: true
  #values: array:318 [▼
    "logger" => Closure {#36 ▶}
    "routes" => Closure {#9 ▶}
    "controllers" => Closure {#11 ▶}
    "controllers_factory" => Closure {#12 ▶}
    "route_class" => "Silex\Route"
    "route_factory" => Closure {#13 ▶}
    "exception_handler" => Closure {#15 ▶}
    "dispatcher_class" => "Symfony\Component\EventDispatcher\EventDispatcher"
    "dispatcher" => Closure {#1186 ▶}
    "callback_resolver" => Closure {#19 ▶}
    "resolver" => Closure {#588 ▶}
    "kernel" => Closure {#23 ▶}
    "request_stack" => Closure {#25 ▶}
    "request_context" => Closure {#27 ▶}
    "url_matcher" => Closure {#29 ▶}
    "request_error" => Closure {#31 ▶}
    "request" => Request {#1139 ▶}
    "request.http_port" => 80
    "request.https_port" => 443
    "debug" => true
    "charset" => "UTF-8"
    "locale" => "ja"
    "config" => Closure {#1026 ▶}
    "monolog.handler.debug" => Closure {#38 ▶}
    "monolog.logger.class" => "Symfony\Bridge\Monolog\Logger"
    "monolog" => Closure {#39 ▶}
    "monolog.handler" => Closure {#44 ▶}
    "monolog.level" => Closure {#41 ▶}
    "monolog.listener" => Closure {#43 ▶}
    "monolog.name" => "myapp"
    "monolog.bubble" => true
    "monolog.permission" => null
    "listener.requestdump" => Closure {#45 ▶}
    "monolog.logfile" => "/XXXX/XXXX/ECCUBEROOT/src/Eccube/../../app/log/site.log"
    "translator" => Closure {#54 ▶}
    "translator.resources" => Closure {#50 ▶}
    "translator.message_selector" => Closure {#52 ▶}
    "translator.domains" => []
    "locale_fallbacks" => array:1 [▶]
    "translator.cache_dir" => null
    "session.test" => false
    "session" => Closure {#57 ▶}
    "session.storage.handler" => Closure {#64 ▶}
    "session.storage.native" => Closure {#61 ▶}
    "session.storage.test" => Closure {#63 ▶}
    "session.storage.options" => array:5 [▶]
    "session.default_locale" => "en"
    "session.storage.save_path" => null
    "session.db_options" => array:1 [▶]
    "twig.options" => array:3 [▶]
    "twig.form.templates" => array:1 [▶]
    "twig.path" => []
    "twig.templates" => []
    "twig" => Closure {#658 ▶}
    "twig.loader.filesystem" => Closure {#1153 ▶}
    "twig.loader.array" => Closure {#69 ▶}
    "twig.loader" => Closure {#71 ▶}
    "fragment.handler" => Closure {#86 ▶}
    "fragment.renderer.inline" => Closure {#88 ▶}
    "fragment.renderer.hinclude" => Closure {#90 ▶}
    "fragment.renderer.esi" => Closure {#92 ▶}
    "fragment.listener" => Closure {#94 ▶}
    "uri_signer" => Closure {#96 ▶}
    "uri_signer.secret" => "e777a79cd661dbad23978972d11ee82d"
    "fragment.path" => "/_fragment"
    "fragment.renderer.hinclude.global_template" => null
    "fragment.renderers" => Closure {#98 ▶}
    "url_generator" => Closure {#101 ▶}
    "form.secret" => "e777a79cd661dbad23978972d11ee82d"
    "form.types" => Closure {#584 ▶}
    "form.type.extensions" => Closure {#1113 ▶}
    "form.type.guessers" => Closure {#108 ▶}
    "form.extension.csrf" => Closure {#110 ▶}
    "form.extensions" => Closure {#176 ▶}
    "form.factory" => Closure {#114 ▶}
    "form.resolved_type_factory" => Closure {#1082 ▶}
    "form.csrf_provider" => Closure {#118 ▶}
    "serializer" => Closure {#121 ▶}
    "serializer.encoders" => Closure {#123 ▶}
    "serializer.normalizers" => Closure {#125 ▶}
    "validator" => Closure {#128 ▶}
    "validator.mapping.class_metadata_factory" => Closure {#130 ▶}
    "validator.validator_factory" => Closure {#132 ▶}
    "validator.object_initializers" => Closure {#181 ▶}
    "swiftmailer.options" => array:7 [▶]
    "swiftmailer.use_spool" => true
    "mailer.initialized" => true
    "mailer" => Closure {#142 ▶}
    "swiftmailer.spooltransport" => Closure {#144 ▶}
    "swiftmailer.spool" => Closure {#146 ▶}
    "swiftmailer.transport" => Closure {#148 ▶}
    "swiftmailer.transport.buffer" => Closure {#150 ▶}
    "swiftmailer.transport.authhandler" => Closure {#152 ▶}
    "swiftmailer.transport.eventdispatcher" => Closure {#154 ▶}
    "db.default_options" => array:5 [▶]
    "dbs.options.initializer" => Closure {#157 ▶}
    "dbs" => Closure {#159 ▶}
    "dbs.config" => Closure {#161 ▶}
    "dbs.event_manager" => Closure {#163 ▶}
    "db" => Closure {#165 ▶}
    "db.config" => Closure {#167 ▶}
    "db.event_manager" => Closure {#169 ▶}
    "dbs.options" => array:2 [▶]
    "doctrine" => Closure {#173 ▶}
    "doctrine.orm.validator.unique_validator" => Closure {#177 ▶}
    "validator.validator_service_ids" => array:2 [▶]
    "orm.proxies_dir" => "/XXXX/XXXX/ECCUBEROOT/src/Eccube/../../app/cache/doctrine"
    "orm.proxies_namespace" => "DoctrineProxy"
    "orm.auto_generate_proxies" => true
    "orm.default_cache" => "array"
    "orm.custom.functions.string" => []
    "orm.custom.functions.numeric" => []
    "orm.custom.functions.datetime" => []
    "orm.custom.hydration_modes" => []
    "orm.class_metadata_factory_name" => "Doctrine\ORM\Mapping\ClassMetadataFactory"
    "orm.default_repository_class" => "Doctrine\ORM\EntityRepository"
    "orm.em.default_options" => array:3 [▶]
    "orm.ems.options.initializer" => Closure {#192 ▶}
    "orm.em_name_from_param_key" => Closure {#190 ▶}
    "orm.ems" => Closure {#196 ▶}
    "orm.ems.config" => Closure {#197 ▶}
    "orm.cache.configurer" => Closure {#199 ▶}
    "orm.cache.locator" => Closure {#201 ▶}
    "orm.cache.factory.backing_memcache" => Closure {#203 ▶}
    "orm.cache.factory.memcache" => Closure {#205 ▶}
    "orm.cache.factory.backing_memcached" => Closure {#207 ▶}
    "orm.cache.factory.memcached" => Closure {#209 ▶}
    "orm.cache.factory.backing_redis" => Closure {#211 ▶}
    "orm.cache.factory.redis" => Closure {#213 ▶}
    "orm.cache.factory.array" => Closure {#215 ▶}
    "orm.cache.factory.apc" => Closure {#217 ▶}
    "orm.cache.factory.xcache" => Closure {#219 ▶}
    "orm.cache.factory.filesystem" => Closure {#221 ▶}
    "orm.cache.factory" => Closure {#223 ▶}
    "orm.mapping_driver_chain.locator" => Closure {#225 ▶}
    "orm.mapping_driver_chain.factory" => Closure {#227 ▶}
    "orm.add_mapping_driver" => Closure {#229 ▶}
    "orm.generate_psr0_mapping" => Closure {#231 ▶}
    "orm.strategy.naming" => Closure {#233 ▶}
    "orm.strategy.quote" => Closure {#235 ▶}
    "orm.entity_listener_resolver" => Closure {#237 ▶}
    "orm.repository_factory" => Closure {#239 ▶}
    "orm.em" => Closure {#578 ▶}
    "orm.em.config" => Closure {#243 ▶}
    "orm.em.options" => array:1 [▶]
    "security.role_hierarchy" => []
    "security.access_rules" => array:6 [▶]
    "security.hide_user_not_found" => true
    "security.authorization_checker" => Closure {#244 ▶}
    "security.token_storage" => Closure {#246 ▶}
    "security" => Closure {#248 ▶}
    "user" => Closure {#448 ▶}
    "security.authentication_manager" => Closure {#251 ▶}
    "security.encoder_factory" => Closure {#446 ▶}
    "security.encoder.digest" => Closure {#255 ▶}
    "security.user_checker" => Closure {#257 ▶}
    "security.access_manager" => Closure {#468 ▶}
    "security.voters" => Closure {#466 ▶}
    "security.firewall" => Closure {#263 ▶}
    "security.channel_listener" => Closure {#265 ▶}
    "security.authentication_listener.factory.logout" => Closure {#267 ▶}
    "security.authentication_listener.factory.pre_auth" => Closure {#269 ▶}
    "security.authentication_listener.factory.form" => Closure {#271 ▶}
    "security.authentication_listener.factory.http" => Closure {#273 ▶}
    "security.authentication_listener.factory.remember_me" => Closure {#184 ▶}
    "security.authentication_listener.factory.anonymous" => Closure {#277 ▶}
    "security.firewall_map" => Closure {#279 ▶}
    "security.access_listener" => Closure {#281 ▶}
    "security.access_map" => Closure {#283 ▶}
    "security.trust_resolver" => Closure {#285 ▶}
    "security.session_strategy" => Closure {#287 ▶}
    "security.http_utils" => Closure {#289 ▶}
    "security.last_error" => Closure {#291 ▶}
    "security.context_listener._proto" => Closure {#293 ▶}
    "security.user_provider.inmemory._proto" => Closure {#295 ▶}
    "security.exception_listener._proto" => Closure {#297 ▶}
    "security.authentication.success_handler._proto" => Closure {#299 ▶}
    "security.authentication.failure_handler._proto" => Closure {#301 ▶}
    "security.authentication_listener.form._proto" => Closure {#303 ▶}
    "security.authentication_listener.http._proto" => Closure {#305 ▶}
    "security.authentication_listener.anonymous._proto" => Closure {#307 ▶}
    "security.authentication.logout_handler._proto" => Closure {#309 ▶}
    "security.authentication_listener.logout._proto" => Closure {#311 ▶}
    "security.authentication_listener.switch_user._proto" => Closure {#313 ▶}
    "security.entry_point.form._proto" => Closure {#315 ▶}
    "security.entry_point.http._proto" => Closure {#317 ▶}
    "security.authentication_provider.dao._proto" => Closure {#319 ▶}
    "security.authentication_provider.anonymous._proto" => Closure {#321 ▶}
    "security.validator.user_password_validator" => Closure {#323 ▶}
    "security.remember_me.response_listener" => Closure {#183 ▶}
    "security.remember_me.service._proto" => Closure {#274 ▶}
    "security.authentication_listener.remember_me._proto" => Closure {#324 ▶}
    "security.authentication_provider.remember_me._proto" => Closure {#326 ▶}
    "orm.ems.options" => array:1 [▶]
    "orm.ems.default" => "default"
    "orm.cache.instances.default.metadata" => ArrayCache {#331 ▶}
    "orm.cache.instances.default.query" => ArrayCache {#329 ▶}
    "orm.cache.instances.default.result" => ArrayCache {#332 ▶}
    "orm.cache.instances.default.hydration" => ArrayCache {#333 ▶}
    "orm.mapping_driver_chain.instances.default" => MappingDriverChain {#338 ▶}
    "dbs.default" => "default"
    "security.firewalls" => array:2 [▶]
    "eccube.password_encoder" => Closure {#444 ▶}
    "eccube.event_listner.security" => Closure {#252 ▶}
    "authority_voter" => Closure {#464 ▶}
    "eccube.service.system" => Closure {#469 ▶}
    "view" => Closure {#471 ▶}
    "eccube.service.cart" => Closure {#473 ▶}
    "eccube.service.order" => Closure {#475 ▶}
    "eccube.service.tax_rule" => Closure {#477 ▶}
    "eccube.service.plugin" => Closure {#479 ▶}
    "eccube.service.mail" => Closure {#481 ▶}
    "eccube.service.csv.export" => Closure {#483 ▶}
    "eccube.service.shopping" => Closure {#485 ▶}
    "eccube.repository.master.authority" => Closure {#487 ▶}
    "eccube.repository.master.tag" => Closure {#489 ▶}
    "eccube.repository.master.pref" => Closure {#491 ▶}
    "eccube.repository.master.sex" => Closure {#493 ▶}
    "eccube.repository.master.disp" => Closure {#495 ▶}
    "eccube.repository.master.product_type" => Closure {#497 ▶}
    "eccube.repository.master.page_max" => Closure {#499 ▶}
    "eccube.repository.master.order_status" => Closure {#501 ▶}
    "eccube.repository.master.device_type" => Closure {#503 ▶}
    "eccube.repository.master.csv_type" => Closure {#505 ▶}
    "eccube.repository.delivery" => Closure {#507 ▶}
    "eccube.repository.delivery_date" => Closure {#509 ▶}
    "eccube.repository.delivery_fee" => Closure {#511 ▶}
    "eccube.repository.delivery_time" => Closure {#513 ▶}
    "eccube.repository.payment" => Closure {#515 ▶}
    "eccube.repository.payment_option" => Closure {#517 ▶}
    "eccube.repository.category" => Closure {#519 ▶}
    "eccube.repository.customer" => Closure {#521 ▶}
    "eccube.repository.news" => Closure {#523 ▶}
    "eccube.repository.mail_history" => Closure {#525 ▶}
    "eccube.repository.member" => Closure {#527 ▶}
    "eccube.repository.order" => Closure {#553 ▶}
    "eccube.repository.product" => Closure {#531 ▶}
    "eccube.repository.product_image" => Closure {#533 ▶}
    "eccube.repository.product_class" => Closure {#535 ▶}
    "eccube.repository.product_stock" => Closure {#537 ▶}
    "eccube.repository.class_name" => Closure {#539 ▶}
    "eccube.repository.class_category" => Closure {#541 ▶}
    "eccube.repository.customer_favorite_product" => Closure {#543 ▶}
    "eccube.repository.base_info" => Closure {#545 ▶}
    "eccube.repository.tax_rule" => Closure {#547 ▶}
    "eccube.repository.page_layout" => Closure {#549 ▶}
    "eccube.repository.block" => Closure {#551 ▶}
    "eccube.repository.customer_address" => Closure {#528 ▶}
    "eccube.repository.shipping" => Closure {#555 ▶}
    "eccube.repository.customer_status" => Closure {#557 ▶}
    "eccube.repository.order_status" => Closure {#559 ▶}
    "eccube.repository.mail_template" => Closure {#561 ▶}
    "eccube.repository.csv" => Closure {#563 ▶}
    "eccube.repository.template" => Closure {#565 ▶}
    "eccube.repository.authority_role" => Closure {#567 ▶}
    "paginator" => Closure {#569 ▶}
    "eccube.repository.help" => Closure {#571 ▶}
    "eccube.repository.plugin" => Closure {#573 ▶}
    "eccube.repository.plugin_event_handler" => Closure {#575 ▶}
    "eccube.event.dispatcher" => Closure {#993 ▶}
    "profiler.mount_prefix" => "/_profiler"
    "data_collector.templates" => array:12 [▶]
    "data_collectors" => array:12 [▶]
    "data_collectors.form.extractor" => Closure {#1065 ▶}
    "twig.profiler.profile" => Closure {#1110 ▶}
    "web_profiler.controller.profiler" => Closure {#1104 ▶}
    "web_profiler.controller.router" => Closure {#1100 ▶}
    "web_profiler.controller.exception" => Closure {#1081 ▶}
    "web_profiler.toolbar.listener" => Closure {#1084 ▶}
    "profiler" => Closure {#1120 ▶}
    "profiler.storage" => Closure {#1122 ▶}
    "profiler.request_matcher" => null
    "profiler.only_exceptions" => false
    "profiler.only_master_requests" => false
    "web_profiler.debug_toolbar.enable" => true
    "web_profiler.debug_toolbar.position" => "bottom"
    "web_profiler.debug_toolbar.intercept_redirects" => false
    "profiler.listener" => Closure {#1124 ▶}
    "stopwatch" => Closure {#1126 ▶}
    "code.file_link_format" => null
    "profiler.templates_path" => Closure {#1133 ▶}
    "profiler.cache_dir" => "/XXXX/XXXX/ECCUBEROOT/html/../app/cache/profiler"
    "var_dumper.cloner" => Closure {#1136 ▶}
    "data_collector.dump" => Closure {#1071 ▶}
    "debug.templates_path" => Closure {#1146 ▶}
    "debug.max_items" => -1
    "debug.max_string_length" => -1
    "security.user_provider.admin" => MemberRepository {#397 ▶}
    "security.context_listener.admin" => Closure {#1189 ▶}
    "security.entry_point.admin.form" => Closure {#1191 ▶}
    "security.authentication_listener.admin.form" => Closure {#1193 ▶}
    "security.authentication_provider.admin.dao" => Closure {#1195 ▶}
    "security.authentication_listener.admin.logout" => Closure {#1197 ▶}
    "security.authentication_listener.admin.anonymous" => Closure {#1199 ▶}
    "security.authentication_provider.admin.anonymous" => Closure {#1201 ▶}
    "security.exception_listener.admin" => Closure {#1203 ▶}
    "security.user_provider.customer" => CustomerRepository {#443 ▶}
    "security.context_listener.customer" => Closure {#1205 ▶}
    "security.entry_point.customer.form" => Closure {#1207 ▶}
    "security.authentication_listener.customer.form" => Closure {#1209 ▶}
    "security.authentication_provider.customer.dao" => Closure {#1211 ▶}
    "security.authentication_listener.customer.logout" => Closure {#1213 ▶}
    "security.remember_me.service.customer" => Closure {#1215 ▶}
    "security.authentication_listener.customer.remember_me" => Closure {#1217 ▶}
    "security.authentication_provider.customer.remember_me" => Closure {#1219 ▶}
    "security.authentication_listener.customer.anonymous" => Closure {#1221 ▶}
    "security.authentication_provider.customer.anonymous" => Closure {#1223 ▶}
    "security.exception_listener.customer" => Closure {#1225 ▶}
    "security.authentication_providers" => array:5 [▶]
    "security.authentication.logout_handler.admin" => Closure {#1249 ▶}
    "security.authentication.success_handler.admin" => Closure {#591 ▶}
    "security.authentication.failure_handler.admin" => Closure {#992 ▶}
    "session.storage" => NativeSessionStorage {#980 ▶}
    "security.authentication.logout_handler.customer" => Closure {#922 ▶}
    "security.authentication.success_handler.customer" => Closure {#910 ▶}
    "security.authentication.failure_handler.customer" => Closure {#906 ▶}
    "twig.form.engine" => Closure {#766 ▶}
    "twig.form.renderer" => Closure {#762 ▶}
  ]
}

Application.phpでDIでセットしたものが格納されています。 そのため、$app['orm.em]とするとEntityManagerなどが呼び出されるわけです。

最初はとまどうかもしれませんが、こちらはこういうものだと覚えておいてください。