SPL(Standard PHP Library)
SPL(Standard PHP Library)
PHP로 코드를 짜다 보면 "이런 자료 구조나 인터페이스가 이미 있으면 좋겠다" 싶을 때가 많아요. SPL은 그러한 흔히 겪는 문제를 풀기 위한 인터페이스와 클래스들을 모아둔 표준 확장이에요.
출처: SPL
본문
SPL(Standard PHP Library, 표준 PHP 라이브러리) 확장은 흔히 마주치는 문제를 풀기 위한 인터페이스와 클래스를 정의해요. 다양한 자료 구조(datastructures), 일반적인 예외(generic exceptions), 반복자(iterators), 객체 지향 API로 파일 시스템을 다루는 클래스, 그리고 유틸리티 함수를 제공해요.
인터페이스(Interfaces)
OuterIterator— OuterIterator 인터페이스RecursiveIterator— RecursiveIterator 인터페이스SeekableIterator— SeekableIterator 인터페이스SplObserver— SplObserver 인터페이스SplSubject— SplSubject 인터페이스
자료 구조(Datastructures)
SplDoublyLinkedList— SplDoublyLinkedList 클래스SplStack— SplStack 클래스SplQueue— SplQueue 클래스SplHeap— SplHeap 클래스SplMaxHeap— SplMaxHeap 클래스SplMinHeap— SplMinHeap 클래스SplPriorityQueue— SplPriorityQueue 클래스SplFixedArray— SplFixedArray 클래스ArrayObject— ArrayObject 클래스SplObjectStorage— SplObjectStorage 클래스
예외(Exceptions)
BadFunctionCallException— BadFunctionCallException 클래스BadMethodCallException— BadMethodCallException 클래스DomainException— DomainException 클래스InvalidArgumentException— InvalidArgumentException 클래스LengthException— LengthException 클래스LogicException— LogicException 클래스OutOfBoundsException— OutOfBoundsException 클래스OutOfRangeException— OutOfRangeException 클래스OverflowException— OverflowException 클래스RangeException— RangeException 클래스RuntimeException— RuntimeException 클래스UnderflowException— UnderflowException 클래스UnexpectedValueException— UnexpectedValueException 클래스
반복자(Iterators)
AppendIterator— AppendIterator 클래스ArrayIterator— ArrayIterator 클래스CachingIterator— CachingIterator 클래스CallbackFilterIterator— CallbackFilterIterator 클래스DirectoryIterator— DirectoryIterator 클래스EmptyIterator— EmptyIterator 클래스FilesystemIterator— FilesystemIterator 클래스FilterIterator— FilterIterator 클래스GlobIterator— GlobIterator 클래스InfiniteIterator— InfiniteIterator 클래스IteratorIterator— IteratorIterator 클래스LimitIterator— LimitIterator 클래스MultipleIterator— MultipleIterator 클래스NoRewindIterator— NoRewindIterator 클래스ParentIterator— ParentIterator 클래스RecursiveArrayIterator— RecursiveArrayIterator 클래스RecursiveCachingIterator— RecursiveCachingIterator 클래스RecursiveCallbackFilterIterator— RecursiveCallbackFilterIterator 클래스RecursiveDirectoryIterator— RecursiveDirectoryIterator 클래스RecursiveFilterIterator— RecursiveFilterIterator 클래스RecursiveIteratorIterator— RecursiveIteratorIterator 클래스RecursiveRegexIterator— RecursiveRegexIterator 클래스RecursiveTreeIterator— RecursiveTreeIterator 클래스RegexIterator— RegexIterator 클래스
파일 처리(File Handling)
SplFileInfo— SplFileInfo 클래스SplFileObject— SplFileObject 클래스SplTempFileObject— SplTempFileObject 클래스
SPL 함수(SPL Functions)
class_implements— 주어진 클래스나 인터페이스가 구현한 인터페이스를 반환해요(Return the interfaces which are implemented by the given class or interface).class_parents— 주어진 클래스의 부모 클래스를 반환해요(Return the parent classes of the given class).class_uses— 주어진 클래스가 사용하는 트레이트를 반환해요(Return the traits used by the given class).iterator_apply— 반복자의 모든 요소에 대해 함수를 호출해요(Call a function for every element in an iterator).iterator_count— 반복자의 요소 수를 세요(Count the elements in an iterator).iterator_to_array— 반복자를 배열로 복사해요(Copy the iterator into an array).spl_autoload—__autoload()의 기본 구현(Default implementation for __autoload()).spl_autoload_call— 등록된 모든__autoload()함수를 시도해 요청한 클래스를 로드해요(Try all registered __autoload() functions to load the requested class).spl_autoload_extensions— spl_autoload용 기본 파일 확장자를 등록·반환해요(Register and return default file extensions for spl_autoload).spl_autoload_functions— 등록된 모든__autoload()함수를 반환해요(Return all registered __autoload() functions).spl_autoload_register— 주어진 함수를__autoload()구현으로 등록해요(Register given function as __autoload() implementation).spl_autoload_unregister— 주어진 함수를__autoload()구현에서 등록 해제해요(Unregister given function as __autoload() implementation).spl_classes— 사용 가능한 SPL 클래스를 반환해요(Return available SPL classes).spl_object_hash— 주어진 객체의 해시 id를 반환해요(Return hash id for given object).spl_object_id— 주어진 객체의 정수 객체 핸들을 반환해요(Return the integer object handle for given object).
더 알아보기
SplQueue/SplStack처럼 자료 구조를 필요할 때 바로 쓰면 배열을 직접 다루는 것보다 의도가 분명해져요.spl_autoload_register는 오토로딩(autoloading)을 직접 구성할 때 자주 쓰이는 함수예요. 컴포저(Composer)와의 관계도 함께 알아두면 좋아요.