Files
doomemacs/modules/lang/php/config.el
Henrik Lissner 9e5e4cf78b refactor!(php): remove php-extras
BREAKING CHANGE: The PHP API data file no longer exists on php.net, and
there is no substitute, and php-extras is no longer maintained, so this
package is defunct and leaves php buffers in an error state. This
deprives non-LSP users from eldoc and naive code completion. The
alternative is to simply adopt LSP.
2025-08-30 00:56:03 +02:00

127 lines
3.6 KiB
EmacsLisp

;;; lang/php/config.el -*- lexical-binding: t; -*-
(defvar +php-default-docker-container "php-fpm"
"The default docker container to run commands in.")
(defvar +php-default-docker-compose "docker-compose.yml"
"Path to docker-compose file.")
(defvar +php-run-tests-in-docker nil
"Whether or not to run tests in a docker environment")
;; DEPRECATED: Remove when projectile is replaced with project.el
(after! projectile
(add-to-list 'projectile-project-root-files "composer.json"))
;;
;;; Packages
(use-package! php-mode
:mode "\\.inc\\'"
:config
;; Disable HTML compatibility in php-mode. `web-mode' has superior support for
;; php+html. Use the .phtml extension instead.
(setq php-mode-template-compatibility nil)
(set-docsets! 'php-mode "PHP" "PHPUnit" "Laravel" "CakePHP" "CodeIgniter" "Doctrine_ORM")
(set-repl-handler! 'php-mode #'+php/open-repl)
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
(set-ligatures! 'php-mode
;; Functional
:lambda "function()" :lambda "fn"
:def "function"
;; Types
:null "null"
:true "true" :false "false"
:int "int" :float "float"
:str "string"
:bool "list"
;; Flow
:not "!"
:and "&&" :and "and"
:or "||" :or "or"
:for "for"
:return "return"
:yield "use")
(when (modulep! +lsp)
(when (executable-find "php-language-server.php")
(setq lsp-clients-php-server-command "php-language-server.php"))
(add-hook 'php-mode-local-vars-hook #'lsp! 'append))
(when (modulep! +tree-sitter)
(add-hook 'php-mode-local-vars-hook #'tree-sitter! 'append))
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
(setq-hook! 'php-mode-hook sp-max-pair-length 5)
(sp-with-modes '(php-mode)
(sp-local-pair "<?" "?>" :post-handlers '(("| " "SPC" "=") ("||\n[i]" "RET") ("[d2]" "p")))
(sp-local-pair "<?php" "?>" :post-handlers '(("| " "SPC") ("||\n[i]" "RET"))))
(map! :localleader
:map php-mode-map
:prefix ("t" . "test")
"r" #'phpunit-current-project
"a" #'phpunit-current-class
"s" #'phpunit-current-test))
(use-package! php-refactor-mode
:hook php-mode
:config
(map! :localleader
:map php-refactor-mode-map
:prefix "r"
"cv" #'php-refactor--convert-local-to-instance-variable
"u" #'php-refactor--optimize-use
"xm" #'php-refactor--extract-method
"rv" #'php-refactor--rename-local-variable))
(use-package! hack-mode
:when (modulep! +hack)
:mode "\\.hh\\'")
(use-package! composer
:defer t
:init
(map! :after php-mode
:localleader
:map php-mode-map
:prefix ("c" . "composer")
"c" #'composer
"i" #'composer-install
"r" #'composer-require
"u" #'composer-update
"d" #'composer-dump-autoload
"s" #'composer-run-script
"v" #'composer-run-vendor-bin-command
"o" #'composer-find-json-file
"l" #'composer-view-lock-file))
;;
;; Projects
(def-project-mode! +php-laravel-mode
:modes '(php-mode yaml-mode web-mode nxml-mode js2-mode scss-mode)
:files (and "artisan" "server.php"))
(def-project-mode! +php-composer-mode
:modes '(web-mode php-mode)
:files ("composer.json"))
(def-project-mode! +phpunit-docker-compose-mode
:when +php-run-tests-in-docker
:modes '(php-mode docker-compose-mode)
:files (and "phpunit.xml" (or +php-default-docker-compose "docker-compose.yml"))
:on-enter
(setq phpunit-args `("exec" ,+php-default-docker-container "php" "vendor/bin/phpunit")
phpunit-executable (executable-find "docker-compose"))
:on-exit
(setq phpunit-args nil
phpunit-executable nil))