반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Kurogo Tutorial 19 - The Kurogo Object -

2012. 6. 12. 05:10 | Posted by 솔웅


반응형

The Kurogo Object


쿠로고 객체는 싱글턴 인스턴스 입니다. 이 객체는 모듈을 개발 할 떄 사용하는 일반적인 태스크인 여러개의 메소드들을 포함하고 있습니다.


Static Class Methods

  • Kurogo::sharedInstance() - shared Kurogo singleton object를 return 합니다. This is typically not necessary to use since all publically documented methods are static methods on the Kurogo class.
  • Kurogo::tempDirectory() - configured temporary directoryt를 return 합니다.
  • Kurogo::siteTimezone() - DateTimeZone object set를 세팅된 site의 세팅된 time zone으로 return 합니다.
  • Kurogo::includePackage($packageName) - Adds a library package to the autoloading path. See The AutoLoader
  • Kurogo::getSiteVar($key, $section=null) - See Configuration
  • Kurogo::getOptionalSiteVar($key, $default=’‘, $section=null) - See Configuration
  • Kurogo::getSiteSection($section) - See Configuration
  • Kurogo::getOptionalSiteSection($section) See Configuration
  • Kurogo::getSiteString($key) - See Configuration
  • Kurogo::getOptionalSiteString($key, $default=’‘) - See Configuration
  • Kurogo::getCache($key) - Retrieves a value from the memory cache - See Caching
  • Kurogo::setCache($key, $value, $ttl = null) - Sets a value to the memory cache - See Caching
  • Kurogo::deleteCache($key) -Removes a value from the memory cache - See Caching
  • Kurogo::log($priority, $message, $area) - Logs a value to the kurogo log - See Logging in Kurogo
  • Kurogo::encrypt($value, key) - Encrypts a value (requires the mcrypt extension). See Encryption
  • Kurogo::decrypt($value, key) - Decrypts a value (requires the mcrypt extension). See Encryption



The AutoLoader


PHP 클래스를 사용하기 전에 클래서 정의가 로드돼 있어야 한다는 것을 기억하세요. 쿠로고는 그 클래스의 이름과 같은 PHP 파일 인 각 클래스를 포함하는 패턴을 따릅니다. 파일들을 활용하기 위해 PHP의 require와 include 구문을 사용할 수 있도록 Kurogo는 클래스가 request 됐을 때 그 파일을 자동으로 include하는 autoloading 메카니즘을 가지고 있습니다. autoloader는 site의 lib 폴더나 base Kurogo lib 폴더를 찾을 겁니다.  그리고 그 클래스와 같은 이름의 파일을 로드할 겁니다. 그러므로 SomeClass::method()로 call을 하면 아래와 같은 파일들을 찾을 겁니다.

  • SITE_DIR/lib/SomeClass.php
  • KurogoRoot/lib/SomeClass.php


Packages


클래스 파일들의 구성을 좀 더 유용하게 하기 위해 패키지라는 개념을 사용합니다. 이것은 비슷한 기능을 갖는 파일들을 한 그룹으로 묶는 겁니다. package를 include 하면 autoloader가 그 subforlder까지 찾을 겁니다. 또한 그 lib 폴더에 있는 Package.php라는 파일을 로드하려고 할 겁니다. 이렇게 함으로서 글로벌 상수나 글로벌 함수 정의들을 로드할 수 있도록 합니다. 예를 들어 Maps 패키지가 오드되면 다음과 같은 경로가 autoloader 검색 path에 추가 될 겁니다.

  • SITE_DIR/lib/Maps/
  • KurogoRoot/lib/Maps/


그리고 autoloader는 lib/Maps.php를 로드하려고 할 겁니다.

여러분의 여러분 site의 lib 폴더에 간단하게 폴더를 추가 생성함으로써 여러분의 패키지를 생성하실 수 있습니다. 아래 패키지들은 쿠로고에서 제공하는 패키지들입니다.


  • Authentication (included automatically when authentication is enabled)
  • Authorization - for connecting to various OAuth based web services
  • Calendar - includes classes to deal with date and time
  • db - used when you wish to interact with a database
  • Emergency - used by the emergency module
  • Maps - used by the maps module
  • People - used by the people module
  • Video - used by the video module


Encryption

1.4 버전에서는 암호화 된 데이터를 저장하고 retrieve 하기 위한 메소드가 추가 됐습니다. 이것은 보안을 유지하면서 원격 서버로부터 중요한 데이터를 저장하는데 유용하게 이용될 수 있을 겁니다. 이 메소드들은 mcrypt extension 이 필요합니다. 다른 암호화 시스템 처럼 데이터를 암호화하기 위해 사용되는 키들을 보호합니다. 기본적으로는 서버 소프트웨어의 인스톨 경로를 사용해 발생되는 SITE_KEY constant를 사용하게 됩니다. site.ini에서 SITE_KEY를 업데이트 해서 이 key를 세팅할 수 있습니다.


Caching

1.4 버전에서는 in-memory caching을 사용해서 쿠로고의 퍼포먼스를 개선하기 위한 메소드를 추가했습니다. 서버가 특정 확장자들을 포함하고 있으면 configuration 값들과 탬플릿들의 search path들 그리고 remote data values 같은 쿠로고에 의해 사용되는 caching information으로 서버의 퍼포먼스를 크게 개선하실 수 있습니다.


Configuration


쿠로고는 2개의 다른 시스템을 사용해서 caching을 지원합니다.


이 시스템에 대한 configuration은 kurogo.ini의 [cache] 섹션을 통해서 완료 됩니다.

chaching types에 의해 사용되는 몇개의 옵션들이 있습니다.

  • CACHE_CLASS - The type of caching system to use. Current options include APCCache and MemcacheCache
  • CACHE_TTL - The default time-to-live (in seconds) for cache values. 특정 시간동안 캐쉬에 값을 보관할 겁니다. 대부분의 경우 10~15분 (600-900)이 적당합니다. 


APC

APCCache 에 대한 추가적인 옵션은 없습니다.


Memcache


이 옵션들은 MemcacheCache에만 적용됩니다.


  • CACHE_HOST - memcache 서버의 hostname 이나 IP address. 이 값이 배열이면(CACHE_HOST[]) 쿠로고는 failover를 할 겁니다. 
  • CACHE_PORT - memcache server에 연결하기 위해 사용되는 포트. default는 11211
  • CACHE_PERSISTENT - 1로 세팅되면 persistent connection이 사용 될 것임. 디폴트는 false
  • CACHE_TIMEOUT - Timeout in seconds to connect to the servers. This should rarely be altered.
  • CACHE_COMPRESSED - If set to 1, compression will be used. Default is true.


반응형