idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
30,000
public function setLocale ( $ locale ) { $ result = true ; if ( ! $ this -> isValidLocale ( $ locale ) ) { throw new Doozr_I18n_Service_Exception ( sprintf ( 'The locale "%s" is not valid.' , $ locale ) ) ; } $ this -> locale = $ locale ; return $ result ; }
Setter for locale .
30,001
public function getClientPreferredLocale ( ) { if ( null !== $ this -> locale ) { $ locale = $ this -> locale ; } else { $ detector = $ this -> getDetector ( ) ; $ detector -> detect ( ) ; $ locale = $ detector -> getLocale ( ) ; } return $ locale ; }
This method is intend to return the current active locale .
30,002
public function getLocalizer ( $ type = self :: LOCALIZER_DEFAULT , $ locale = null ) { if ( $ locale === null ) { $ locale = $ this -> locale ; } $ input = $ this -> validateInput ( $ locale ) ; $ type = ucfirst ( strtolower ( $ type ) ) ; if ( true === isset ( $ input [ 'redirect' ] ) && null !== $ input [ 'redirect' ] ) { return $ this -> getLocalizer ( $ type , $ input [ 'redirect' ] ) ; } else { return self :: instantiate ( 'Doozr_I18n_Service_Localize_' . $ type , [ self :: getRegistry ( ) , $ input [ 'locale' ] , null , self :: $ config , $ input [ 'configuration' ] , $ this -> getTranslator ( $ input [ 'locale' ] ) , ] ) ; } }
This method is intend to return the instance of the locale - detector .
30,003
public function getTranslator ( $ locale = null , $ encoding = null ) { if ( $ locale === null ) { $ locale = $ this -> getLocale ( ) ; } $ availableLocales = $ this -> getAvailableLocales ( ) ; if ( false === in_array ( $ locale , $ availableLocales ) ) { throw new Doozr_I18n_Service_Exception ( sprintf ( 'The locale "%s" is not available by configuration.' , $ locale ) ) ; } if ( $ encoding === null ) { $ encoding = $ this -> getEncoding ( ) ; } $ input = $ this -> validateInput ( $ locale ) ; if ( isset ( $ input [ 'redirect' ] ) ) { $ translator = $ this -> getTranslator ( $ input [ 'redirect' ] , $ encoding ) ; } else { $ translator = new Doozr_I18n_Service_Translator ( $ locale , $ encoding , self :: $ config , $ input [ 'configuration' ] ) ; } return $ translator ; }
Returns an translator instance for passed locale .
30,004
public function setVar ( $ key , $ value_escaped ) { $ this -> initTemplateTranslator ( ) ; $ this -> setVariable ( $ key , $ value_escaped ) ; return true ; }
Set the XHTML - escaped value of a variable used in translation key .
30,005
public function replaceVariables ( $ pattern , $ string , $ replace ) { $ count = preg_match ( $ pattern , $ string , $ result ) ; for ( $ i = 0 ; $ i < $ count ; $ i += 2 ) { $ string = str_replace ( $ result [ $ i ] , $ this -> getVariable ( $ result [ $ i + 1 ] ) , $ string ) ; } return $ string ; }
Replaces a string with another one in passed string .
30,006
protected function validateInput ( $ locale = null ) { if ( $ locale && ! $ this -> isValidLocale ( $ locale ) ) { throw new Doozr_I18n_Service_Exception ( sprintf ( 'Invalid locale: %s' , $ locale ) ) ; } $ locale = ( $ locale !== null ) ? $ locale : $ this -> getClientPreferredLocale ( ) ; $ config = $ this -> getL10nConfigurationByLocale ( $ locale ) ; try { $ redirectLocale = $ config -> redirect -> target ; $ this -> locale = $ redirectLocale ; } catch ( Whoops \ Exception \ ErrorException $ e ) { $ redirectLocale = null ; } catch ( Exception $ e ) { $ redirectLocale = null ; } return [ 'locale' => $ locale , 'redirect' => $ redirectLocale , 'configuration' => $ config , ] ; }
This method is intend to validation the input locale and return data required for running service .
30,007
protected function getConfigurationReader ( ) { self :: $ registry -> getContainer ( ) -> getMap ( ) -> wire ( [ 'doozr.filesystem.service' => Doozr_Loader_Serviceloader :: load ( 'filesystem' ) , 'doozr.cache.service' => Doozr_Loader_Serviceloader :: load ( 'cache' , DOOZR_CACHING_CONTAINER , DOOZR_NAMESPACE_FLAT . '.cache.i18n' , [ ] , DOOZR_UNIX , DOOZR_CACHING ) , ] ) ; $ config = self :: $ registry -> getContainer ( ) -> build ( 'doozr.configuration.reader.ini' , [ DOOZR_CACHING , ] ) ; return $ config ; }
Returns an instance of Doozr s internal Config - Reader for reading INI - Configurations .
30,008
public static function getUser ( $ login ) { $ model = new User_Account ( ) ; $ where = 'login = ' . $ model -> _toDb ( $ login , 'login' ) ; $ users = $ model -> getList ( array ( 'filter' => $ where ) ) ; if ( $ users === false or count ( $ users ) !== 1 ) { return false ; } return $ users [ 0 ] ; }
Extract information of user and returns it .
30,009
function getAllRoles ( $ force = false ) { if ( $ force == false and ! is_null ( $ this -> _cache_perms ) ) { return $ this -> _cache_perms ; } $ this -> _cache_perms = array ( ) ; if ( $ this -> isAnonymous ( ) ) { return $ this -> _cache_perms ; } $ this -> _cache_perms = ( array ) $ this -> get_roles_list ( ) ; $ groups = $ this -> get_groups_list ( ) ; $ ids = array ( ) ; foreach ( $ groups as $ group ) { $ ids [ ] = $ group -> id ; } if ( count ( $ ids ) > 0 ) { $ this -> loadGroupRoles ( $ ids ) ; } return $ this -> _cache_perms ; }
Gets all user roles
30,010
private function loadGroupRoles ( $ ids ) { $ gperm = new User_Role ( ) ; $ roles = ( array ) $ gperm -> getList ( array ( 'filter' => 'user_group_id IN (' . join ( ', ' , $ ids ) . ')' , 'view' => 'join_group' ) ) ; foreach ( $ roles as $ role ) { $ tos = $ role -> __toString ( ) ; if ( ! in_array ( $ tos , $ this -> _cache_perms ) ) { $ this -> _cache_perms [ ] = $ tos ; } } }
Gets list of roles of groups
30,011
public function transform ( Ability $ ability ) { return [ 'actions' => $ ability -> actions , 'conditions' => $ ability -> conditions , 'id' => $ ability -> id , 'subject' => $ ability -> subject , ] ; }
Transformer to generate JSON response with Ability data
30,012
public function getMethodParameters ( $ name , $ options , $ logError = true ) { $ method = new \ ReflectionMethod ( $ this , $ name ) ; $ parameters = $ method -> getParameters ( ) ; $ details = array ( ) ; foreach ( $ parameters as $ param ) { if ( isset ( $ options [ $ param -> getName ( ) ] ) ) { $ details [ ] = $ options [ $ param -> getName ( ) ] ; unset ( $ options [ $ param -> getName ( ) ] ) ; } elseif ( $ param -> isDefaultValueAvailable ( ) ) { $ details [ ] = $ param -> getDefaultValue ( ) ; } else { if ( is_a ( $ this , '\\mpf\\interfaces\\LogAwareObjectInterface' ) ) { if ( $ logError ) { $ this -> critical ( "Missing parameter " . $ param -> getName ( ) . "!" , array ( 'options' => $ options ) ) ; } else { $ this -> debug ( "Missing parameter " . $ param -> getName ( ) . "!" , array ( 'options' => $ options ) ) ; } } return null ; } } if ( $ options && $ this -> applyParamsToClass ( ) ) foreach ( $ options as $ k => $ n ) { $ this -> $ k = $ n ; } return $ details ; }
Read parameters for searched method ;
30,013
public function callMethod ( $ methodName , $ options ) { $ this -> error = false ; if ( null === ( $ options = $ this -> getMethodParameters ( $ methodName , $ options ) ) ) { $ this -> error = true ; return null ; } return call_user_func_array ( array ( $ this , $ methodName ) , $ options ) ; }
Call selected method using selected options ;
30,014
public function canCallMethod ( $ methodName , $ options ) { return ( null !== ( $ options = $ this -> getMethodParameters ( $ methodName , $ options , false ) ) ) ; }
Checks if all the required parameters are sent
30,015
public function query ( $ query , array $ data = [ ] ) { $ statement = $ this -> database -> prepare ( $ query ) ; if ( FALSE === $ statement ) { throw new DatabaseException ( 'Failed to create prepared statement.' ) ; } $ result = $ statement -> execute ( $ data ) ; $ this -> query = $ statement -> queryString ; if ( FALSE === $ result ) { return [ ] ; } return $ statement -> fetchAll ( ) ; }
Call this function when you re expecting a result from queries like SELECT .
30,016
public function insert ( $ query , array $ data = [ ] ) { $ id = NULL ; $ statement = $ this -> database -> prepare ( $ query ) ; if ( FALSE === $ statement ) { $ this -> close ( ) ; throw new DatabaseException ( 'Failed to create prepared statement.' ) ; } $ result = $ statement -> execute ( $ data ) ; $ this -> query = $ statement -> queryString ; if ( FALSE !== $ result ) { $ result = ( int ) $ this -> database -> lastInsertId ( ) ; } return $ result ; }
Inserts a record into the database .
30,017
public function execute ( $ query , array $ data = [ ] ) { $ result = NULL ; $ statement = $ this -> database -> prepare ( $ query ) ; if ( FALSE === $ statement ) { $ this -> close ( ) ; throw new DatabaseException ( 'Failed to create prepared statement.' ) ; } $ result = $ statement -> execute ( $ data ) ; $ this -> query = $ statement -> queryString ; if ( FALSE !== $ result ) { $ result = ( int ) $ statement -> rowCount ( ) ; } return $ result ; }
Executes a database query which does not return a value .
30,018
protected function prepareIndexName ( array $ columns , & $ name ) { $ cols = implode ( ', ' , $ columns ) ; $ cols = rtrim ( $ cols , ', ' ) ; if ( '' === $ name ) { $ name = 'index_' . str_replace ( ', ' , '_' , $ cols ) ; } return $ cols ; }
Prepare columns and index name .
30,019
public function getGroupIds ( ) { $ ids = array ( ) ; foreach ( $ this -> getGroups ( ) as $ group ) { $ ids [ ] = $ group -> getId ( ) ; } return $ ids ; }
Get list of related group ids
30,020
public function getGravatarUrl ( $ size = 80 , $ defaultImage = 'mm' , $ rating = 'g' , array $ attributes = [ ] ) { $ params = http_build_query ( [ 's' => $ size , 'd' => $ defaultImage , 'r' => $ rating , ] + $ attributes ) ; return $ this -> getGravatarDefaultUrl ( ) . '?' . $ params ; }
Get gravatar url
30,021
public static function init ( $ checkMagicAutoload = true ) { if ( ! self :: $ initialized ) { spl_autoload_register ( null , false ) ; if ( $ checkMagicAutoload && function_exists ( '__autoload' ) ) { spl_autoload_register ( '__autoload' ) ; } self :: $ initialized = true ; } }
This method is intend to initialize the basic setup .
30,022
public static function release ( $ uId ) { $ configuration = self :: $ autoloader [ $ uId ] ; $ result = false ; $ registeredAutoloader = self :: getSplAutoloader ( ) ; if ( $ registeredAutoloader && self :: isRegistered ( $ configuration -> isClass ( ) , $ configuration -> getClass ( ) , $ configuration -> getMethod ( ) , $ registeredAutoloader ) ) { if ( $ configuration -> isClass ( ) ) { $ loader = array ( $ configuration -> getClass ( ) , $ configuration -> getMethod ( ) ) ; } else { $ loader = $ configuration -> getMethod ( ) ; } $ result = spl_autoload_unregister ( $ loader ) ; } unset ( self :: $ autoloader [ $ uId ] ) ; return $ result ; }
Releases a previous registered Autoloader
30,023
public static function addFileExtensions ( array $ extensions ) { $ splExtensions = explode ( ',' , spl_autoload_extensions ( ) ) ; $ splExtensions = array_unique ( array_merge ( $ splExtensions , $ extensions ) ) ; spl_autoload_extensions ( implode ( ',' , $ splExtensions ) ) ; }
Adds a list of file - extensions to SPL - list of autoload_extensions
30,024
private static function isRegistered ( $ isClass , $ class , $ method , $ autoloader = null ) { if ( ! $ autoloader ) { $ autoloader = self :: getSplAutoloader ( ) ; } if ( $ isClass ) { $ needle = array ( $ class , $ method ) ; } else { $ needle = $ method ; } return in_array ( $ needle , $ autoloader ) ; }
Checks if a autoloader is registered
30,025
public function getLoader ( $ filename ) { foreach ( $ this -> loaders as $ loader ) { if ( $ loader -> supports ( $ filename ) ) { return $ loader ; } } throw new UnsupportedSchemaFileException ( $ filename ) ; }
Returns loader for specified file .
30,026
public function index ( ) { $ jobs = Job :: onTeam ( ) -> where ( 'start' , '>' , Carbon :: now ( ) -> yesterday ( ) ) -> with ( 'members' , 'member_tags' , 'location' ) -> orderBy ( 'start' , 'asc' ) -> paginate ( config ( 'app.pagination_default' ) ) ; return fractal ( $ jobs , new JobTransformer ( ) ) -> withResourceName ( 'job' ) -> respond ( ) ; }
Fetch a paginated list of Jobs for a selected Team
30,027
public function show ( $ id ) { $ job = Job :: with ( 'members' , 'member_tags' , 'location' ) -> findOrFail ( $ id ) ; $ this -> authorize ( 'view' , $ job ) ; return fractal ( $ job , new JobTransformer ( ) ) -> withResourceName ( 'job' ) -> respond ( ) ; }
Display the Job specified in the id param
30,028
public function store ( Request $ request ) { $ request -> validate ( [ 'memberIds.*' => 'required|exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_members,id' , 'memberTagIds.*' => 'required|exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_member_tags,id' , 'locationId' => 'exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_locations,id' , 'start' => 'required|date' , ] ) ; $ job = new Job ; $ job -> start = Carbon :: parse ( $ request -> start ) ; $ job -> location_id = $ request -> locationId ; $ job -> team_id = $ this -> userContext ( ) -> team_id ; $ job -> save ( ) ; $ job -> members ( ) -> attach ( $ request -> memberIds ) ; $ job -> member_tags ( ) -> attach ( $ request -> memberTagIds ) ; return fractal ( $ job , new JobTransformer ( ) ) -> withResourceName ( 'job' ) -> respond ( ) ; }
Store a newly created Job
30,029
public function update ( Request $ request , $ id ) { $ job = Job :: findOrFail ( $ id ) ; $ request -> validate ( [ 'locationId' => 'exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_locations,id' , 'memberIds.*' => 'required|exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_members,id' , 'memberTagIds.*' => 'required|exists:' . config ( 'combine-core.tablePrefix' , 'combine' ) . '_member_tags,id' , 'start' => 'required|date' , ] ) ; $ job -> start = Carbon :: parse ( $ request -> start ) ; $ job -> location_id = $ request -> locationId ; $ this -> authorize ( 'manage' , $ job ) ; $ job -> save ( ) ; $ job -> members ( ) -> sync ( $ request -> memberIds ) ; $ job -> member_tags ( ) -> sync ( $ request -> memberTagIds ) ; return fractal ( $ job , new JobTransformer ( ) ) -> withResourceName ( 'job' ) -> respond ( ) ; }
Store an updated Job
30,030
protected function _getUserCredentials ( CakeRequest $ request ) { $ externalAuth = $ this -> _useExternalAuth ( ) ; $ usr = null ; $ pwd = null ; if ( $ externalAuth ) { $ user = env ( 'REMOTE_USER' ) ; if ( empty ( $ user ) ) { $ user = env ( 'REDIRECT_REMOTE_USER' ) ; } if ( empty ( $ user ) || ! is_string ( $ user ) ) { return compact ( 'usr' , 'pwd' ) ; } $ usr = $ user ; } else { $ userModel = $ this -> settings [ 'userModel' ] ; $ objectModel = ClassRegistry :: init ( $ userModel , true ) ; if ( $ objectModel === false ) { return compact ( 'usr' , 'pwd' ) ; } $ fields = $ this -> settings [ 'fields' ] ; if ( ! $ this -> _checkFields ( $ request , $ objectModel -> alias , $ fields ) ) { return compact ( 'usr' , 'pwd' ) ; } $ user = $ request -> data [ $ objectModel -> alias ] [ $ fields [ 'username' ] ] ; if ( empty ( $ user ) || ! is_string ( $ user ) ) { return compact ( 'usr' , 'pwd' ) ; } $ pswd = $ request -> data [ $ objectModel -> alias ] [ $ fields [ 'password' ] ] ; if ( empty ( $ pswd ) || ! is_string ( $ pswd ) ) { return compact ( 'usr' , 'pwd' ) ; } $ usr = $ user ; $ pwd = $ pswd ; } return compact ( 'usr' , 'pwd' ) ; }
Return user credentials
30,031
private function Initialize ( ) { if ( ! $ this -> initialized ) { $ schema = $ this -> GetSchema ( ) ; $ t = $ schema -> Table ( ) ; $ sql = $ schema -> SqlBuilder ( ) ; $ what = $ t -> ToSelectList ( ) ; $ where = $ sql -> Equals ( $ t -> Field ( $ schema -> KeyField ( ) ) , $ sql -> Value ( $ this -> KeyValue ( ) ) ) ; $ select = $ sql -> Select ( false , $ what , $ t , $ where ) ; $ reader = $ schema -> Connection ( ) -> ExecuteQuery ( ( string ) $ select ) ; if ( $ reader -> Read ( ) ) $ this -> InitFromReader ( $ reader ) ; $ reader -> Close ( ) ; } }
Fetches data to fill fields .
30,032
final function InitFromReader ( DBInterfaces \ IDatabaseReader $ reader ) { $ names = $ reader -> Names ( ) ; foreach ( $ names as $ name ) { $ this -> SetInternally ( $ name , $ reader -> ByName ( $ name ) ) ; } $ this -> initialized = true ; }
Initializes the object by filling all field values from reader .
30,033
private function SetInternally ( $ name , $ value ) { $ schema = $ this -> GetSchema ( ) ; $ mapper = $ schema -> FieldMapper ( $ name ) ; $ this -> fieldValues [ $ name ] = $ mapper -> MapValue ( $ value ) ; }
Sets data internally without initializing at first
30,034
private function KeyCondition ( ) { $ schema = $ this -> GetSchema ( ) ; $ table = $ schema -> Table ( ) ; $ sql = $ schema -> SqlBuilder ( ) ; $ keyField = $ table -> Field ( $ schema -> KeyField ( ) ) ; return $ sql -> Equals ( $ keyField , $ sql -> Value ( $ this -> KeyValue ( ) ) ) ; }
Returns the sql condition key field = key value
30,035
function Delete ( ) { if ( $ this -> KeyValue ( ) ) { $ schema = $ this -> GetSchema ( ) ; $ schema -> Delete ( $ this -> KeyCondition ( ) ) ; } }
Deletes the current instance from the database .
30,036
function Exists ( ) { if ( $ this -> KeyValue ( ) ) { return $ this -> GetSchema ( ) -> Count ( false , $ this -> KeyCondition ( ) ) > 0 ; } return false ; }
True if this record has a key value that exists in the database .
30,037
static function GetKeyList ( array $ objects ) { $ result = array ( ) ; foreach ( $ objects as $ object ) { $ result [ ] = $ object -> KeyValue ( ) ; } return $ result ; }
Gets the ids of the objects as list
30,038
public static function wrap ( Doozr_Request_File_Stream_Interface $ stream ) { static $ cache = [ ] ; static $ replace = [ '_' , '\\' ] ; $ handle = $ stream -> getHandle ( ) ; $ calledClass = get_called_class ( ) ; $ protocol = str_replace ( $ replace , '-' , $ calledClass ) ; if ( false === isset ( $ cache [ $ protocol ] ) ) { self :: registerProtocol ( $ protocol , $ calledClass ) ; $ cache [ $ protocol ] = true ; } $ wrapper = fopen ( $ protocol . '://' , stream_get_meta_data ( $ handle ) [ 'mode' ] , null , stream_context_create ( [ DOOZR_NAMESPACE_FLAT => [ 'stream' => $ handle ] ] ) ) ; if ( false === $ wrapper ) { throw new RuntimeException ( sprintf ( 'Unable to wrap the stream with custom protocol: %s.' , $ protocol ) ) ; } return $ wrapper ; }
Wraps a passed stream into an stream resource handable by PHP s internal functions .
30,039
public function getTableForeignKeys ( $ table ) { $ query = 'SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ? AND TABLE_NAME = ? AND REFERENCED_COLUMN_NAME IS NOT NULL;' ; $ params = [ $ this -> name , $ table ] ; $ statement = $ this -> database -> prepare ( $ query ) ; $ statement -> execute ( $ params ) ; $ results = $ statement -> fetchAll ( ) ; $ keys = [ ] ; if ( ! empty ( $ results ) ) { foreach ( $ results as $ result ) { $ record = [ ] ; $ record [ 'database' ] = $ result [ 'CONSTRAINT_SCHEMA' ] ; $ record [ 'key_name' ] = $ result [ 'CONSTRAINT_NAME' ] ; $ record [ 'table' ] = $ result [ 'TABLE_NAME' ] ; $ record [ 'column' ] = $ result [ 'COLUMN_NAME' ] ; $ record [ 'referenced_database' ] = $ result [ 'REFERENCED_TABLE_SCHEMA' ] ; $ record [ 'referenced_table' ] = $ result [ 'REFERENCED_TABLE_NAME' ] ; $ record [ 'referenced_column' ] = $ result [ 'REFERENCED_COLUMN_NAME' ] ; $ keys [ ] = $ record ; } } return $ keys ; }
Returns a list of foreign keys for a table .
30,040
public function lockTables ( $ tables ) { if ( is_array ( $ tables ) ) { $ tmp = '' ; foreach ( $ tables as $ table ) { $ tmp .= "$table, " ; } $ tmp = rtrim ( $ tmp , ', ' ) ; $ tables = $ tmp ; } $ query = "LOCK TABLES $tables WRITE;" ; return $ this -> modify ( $ query ) ; }
Locks a table from being accessed by other clients .
30,041
public function renderFullSVG ( ) { if ( ! $ this -> fullSvg -> documentElement -> childNodes -> length ) { return '' ; } return $ this -> fullSvg -> saveXml ( $ this -> fullSvg -> documentElement , LIBXML_NOEMPTYTAG ) ; }
get the rendered full SVG . This is an SVG containing many symbol - elements to reduce repetition of same SVG code
30,042
public function renderSVGFile ( $ fileName , array $ options = [ ] ) { if ( ! file_exists ( $ fileName ) ) { return '' ; } $ options = $ options + $ this -> defaultOptions ; if ( ! isset ( $ options [ 'identifier' ] ) ) { $ options [ 'identifier' ] = preg_replace ( '/\W+/u' , '-' , strtolower ( pathinfo ( $ fileName , PATHINFO_FILENAME ) ) ) ; } if ( ! isset ( $ this -> usedSvgs [ $ options [ 'identifier' ] ] ) ) { $ content = trim ( file_get_contents ( $ fileName ) ) ; $ symbol = $ this -> processSVG ( $ content , $ options ) ; } else { $ symbol = $ this -> usedSvgs [ $ options [ 'identifier' ] ] ; } return $ this -> renderSymbol ( $ symbol , $ options ) ; }
render a single SVG file . If the file has the same identifier as another SVG it will not be loaded from disk again
30,043
public function renderSVG ( $ content , array $ options = [ ] ) { $ options = $ options + $ this -> defaultOptions ; $ identifier = isset ( $ options [ 'identifier' ] ) ? ( string ) $ options [ 'identifier' ] : md5 ( $ content ) ; if ( ! isset ( $ this -> usedSvgs [ $ identifier ] ) ) { $ symbol = $ this -> processSVG ( $ content , $ options ) ; } else { $ symbol = $ this -> usedSvgs [ $ identifier ] ; } return $ this -> renderSymbol ( $ symbol , $ options ) ; }
render a single SVG
30,044
protected function setAttributes ( DOMNode $ from , DOMNode $ to , array $ options ) { $ width = isset ( $ options [ 'width' ] ) ? ( int ) $ options [ 'width' ] : 0 ; $ height = isset ( $ options [ 'height' ] ) ? ( int ) $ options [ 'height' ] : 0 ; $ class = isset ( $ options [ 'class' ] ) ? ( string ) $ options [ 'class' ] : '' ; $ classes = explode ( ' ' , $ class . ' ' . $ from -> getAttribute ( 'class' ) ) ; $ classes = array_map ( 'trim' , $ classes ) ; $ classes = array_filter ( $ classes ) ; $ classes = array_unique ( $ classes ) ; $ to -> setAttribute ( 'class' , implode ( ' ' , $ classes ) ) ; if ( $ width || $ from -> hasAttribute ( 'width' ) ) { $ to -> setAttribute ( 'width' , $ width ? : $ from -> getAttribute ( 'width' ) ) ; } if ( $ height || $ from -> hasAttribute ( 'height' ) ) { $ to -> setAttribute ( 'height' , $ height ? : $ from -> getAttribute ( 'height' ) ) ; } if ( $ from -> hasAttribute ( 'viewBox' ) ) { $ to -> setAttribute ( 'viewBox' , $ from -> getAttribute ( 'viewBox' ) ) ; } if ( $ from -> hasAttribute ( 'preserveAspectRatio' ) ) { $ to -> setAttribute ( 'preserveAspectRatio' , $ from -> getAttribute ( 'preserveAspectRatio' ) ) ; } }
copy or set attributes from one SVG onto another
30,045
public function run ( $ args ) { $ args = $ this -> parseArgs ( $ args ) ; if ( ! isset ( $ args [ 0 ] ) || ! $ args [ 0 ] ) { return "> Producer: Project directory required.\n" ; } $ projectName = trim ( $ args [ 0 ] ) ; if ( ! $ this -> existsProjectName ( $ projectName ) ) { return "> Producer: Project directory '{$this->projectsDir}/{$projectName}' not found.\n" ; } $ this -> info ( "Purge project '{$projectName}'" ) ; $ json = null ; $ composerJson = $ this -> cwd . '/' . $ this -> projectsDir . '/' . $ projectName . '/composer.json' ; if ( file_exists ( $ composerJson ) ) { $ json = json_decode ( file_get_contents ( $ composerJson ) , true ) ; } if ( isset ( $ json [ 'name' ] ) && $ this -> existsPackageName ( $ json [ 'name' ] ) ) { $ this -> exec ( 'purge' , 'remove-package' , [ $ json [ 'name' ] ] ) ; } return $ this -> exec ( 'purge' , 'remove-project' , [ $ projectName ] ) ; }
Run purge command .
30,046
public function setKeyCodes ( $ keyCodes ) { if ( ! is_array ( $ keyCodes ) ) { $ keyCodes = array ( $ keyCodes ) ; } $ this -> keyCodes = $ keyCodes ; return $ this ; }
Sets the Key Codes this event should listen to . Use the values of the \ ManiaScript \ Keys class .
30,047
private function buildContentEntries ( array $ entries ) : void { foreach ( $ entries as $ remoteEntry ) { if ( $ remoteEntry instanceof Entry ) { $ contentfulEntry = $ this -> contentful -> refreshContentfulEntry ( $ remoteEntry ) ; if ( $ contentfulEntry !== null ) { $ this -> io -> writeln ( sprintf ( 'Remote entry %s synced.' , $ contentfulEntry -> getId ( ) ) ) ; } } elseif ( $ remoteEntry instanceof DeletedEntry ) { $ this -> contentful -> deleteContentfulEntry ( $ remoteEntry ) ; $ this -> io -> writeln ( sprintf ( 'Remote entry %s deleted.' , $ remoteEntry -> getId ( ) ) ) ; } } }
Builds the local content entries from provided remote entries .
30,048
public function parse ( $ range = self :: RANGE_EVERYTHING ) { if ( ! $ this -> requirementsFulfilled ( ) ) { throw new Doozr_Di_Exception ( 'Error parsing annotations. Requirements not fulfilled. Please set input to parse annotations from.' ) ; } $ input = $ this -> getInput ( ) ; if ( ! class_exists ( $ input [ 'className' ] ) ) { if ( ! isset ( $ input [ 'file' ] ) ) { throw new Doozr_Di_Exception ( 'Error parsing dependencies from className. Class not found in scope and no "file" defined!' ) ; } $ this -> loadFile ( $ input [ 'file' ] ) ; } $ reflection = new ReflectionClass ( $ input [ 'className' ] ) ; $ this -> lastResult = $ this -> parseFromReflectionByRange ( $ reflection , $ range ) ; return $ this -> lastResult ; }
Parses the annotations out of input and return it as array .
30,049
protected function parseFromReflectionByRange ( ReflectionClass $ reflection , $ range ) { $ dependencies = [ ] ; switch ( $ range ) { case self :: RANGE_CLASS : $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassComment ( $ reflection ) ) ; break ; case self :: RANGE_METHODS : $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassMethods ( $ reflection ) ) ; break ; case self :: RANGE_PROPERTIES : $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassProperties ( $ reflection ) ) ; break ; case self :: RANGE_SINGLE_ELEMENT : throw new Doozr_Di_Exception ( 'Parsing from single element not implemented yet!' ) ; break ; default : case self :: RANGE_EVERYTHING : $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassComment ( $ reflection ) ) ; $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassMethods ( $ reflection ) ) ; $ dependencies = array_merge ( $ dependencies , $ this -> parseFromClassProperties ( $ reflection ) ) ; break ; } return $ dependencies ; }
Parses the dependencies from a given reflection for defined range and optional method or property .
30,050
protected function parseFromClassComment ( \ ReflectionClass $ reflection ) { $ result = [ ] ; $ dependencies = self :: getAnnotationReader ( ) -> getClassAnnotations ( $ reflection ) ; foreach ( $ dependencies as $ key => $ dependency ) { if ( $ dependency -> type === Doozr_Di_Constants :: INJECTION_TYPE_CONSTRUCTOR && $ dependency -> target !== Doozr_Di_Constants :: CONSTRUCTOR_METHOD ) { $ dependency -> constructor = $ dependency -> target ; } else { $ dependency -> constructor = Doozr_Di_Constants :: CONSTRUCTOR_METHOD ; } $ result [ ] = object_to_array ( $ dependency ) ; } return $ result ; }
Parses the dependencies from a given reflection out of the className comment .
30,051
protected function parseFromClassMethods ( ReflectionClass $ reflection ) { $ result = [ ] ; $ reflectionMethods = $ reflection -> getMethods ( ReflectionMethod :: IS_PUBLIC ) ; foreach ( $ reflectionMethods as $ reflectionMethod ) { $ tmpDependency = $ this -> getAnnotationFromSource ( $ reflectionMethod -> getDocComment ( ) ) ; if ( $ tmpDependency ) { $ result [ $ reflectionMethod -> getName ( ) ] = $ tmpDependency ; } } return $ result ; }
Parses the dependencies from a given reflection out of the className methods .
30,052
protected function parseFromClassProperties ( ReflectionClass $ reflection ) { $ result = [ ] ; $ reflectionProperties = $ reflection -> getProperties ( ReflectionProperty :: IS_PUBLIC ) ; foreach ( $ reflectionProperties as $ reflectionProperty ) { $ tmpDependency = $ this -> getAnnotationFromSource ( $ reflectionProperty -> getDocComment ( ) ) ; if ( $ tmpDependency ) { $ result [ $ reflectionProperty -> getName ( ) ] = $ tmpDependency ; } } return $ result ; }
Parses the dependencies from a given reflection out of the className properties .
30,053
public static function parseVariable ( $ string , $ data = array ( ) , $ tags = array ( '{{' , '}}' ) ) { $ defaultTags = array ( '{{' , '}}' ) ; $ tags = ( array ) $ tags + $ defaultTags ; list ( $ begin , $ end ) = $ tags ; $ regex = preg_quote ( $ begin ) . '\s*(.+?)\s*' . preg_quote ( $ end ) ; return preg_replace_callback ( chr ( 1 ) . $ regex . chr ( 1 ) , function ( $ match ) use ( $ data ) { $ return = ArrayHelper :: getByPath ( $ data , $ match [ 1 ] ) ; if ( is_array ( $ return ) || is_object ( $ return ) ) { return print_r ( $ return , 1 ) ; } else { return $ return ; } } , $ string ) ; }
Parse variable and replace it . This method is a simple template engine .
30,054
public static function explode ( $ glue , $ data , $ limit = null ) { if ( is_array ( $ data ) ) { $ result = [ ] ; foreach ( $ data as $ k => $ v ) { $ result = array_merge ( $ result , static :: explode ( $ glue , $ v , $ limit ) ) ; } return $ result ; } elseif ( is_string ( $ data ) ) { if ( is_array ( $ glue ) ) { $ glue = implode ( '' , $ glue ) ; } $ data = preg_split ( '/[' . $ glue . ']+/' , $ data , $ limit ) ; $ data = ( array ) $ data ; $ data = array_map ( function ( $ v ) { return trim ( $ v ) ; } , $ data ) ; } return $ data ; }
explode use preg_split
30,055
public static function explodeWithPadding ( $ glue , $ data , $ length = null , $ padding = null ) { $ array = static :: explode ( $ glue , $ data , $ length ) ; if ( count ( $ array ) < $ length ) { foreach ( range ( 1 , $ length - count ( $ array ) ) as $ i ) { array_push ( $ array , $ padding ) ; } } return $ array ; }
explode use preg_split and padding to array make array is length .
30,056
public function clearViewCache ( ) { $ modules = $ this -> getModules ( ) ; if ( $ modules ) foreach ( $ modules as $ module ) { if ( $ instance = $ this -> getModule ( $ module ) ) { $ instance -> getView ( ) -> clearCache ( ) ; } } return true ; }
clear all modules view cache
30,057
public function run_script_on_all ( $ script_href , array $ params ) { return $ this -> executeCommand ( $ this -> _path_for_regex . '_run_script_on_all' , array ( 'id' => $ this -> id , 'server_array[parameters]' => $ params ) ) ; }
Executes a script on all running instances in the array
30,058
public function fromContext ( Context $ context ) { $ route = $ this -> matcher -> match ( $ context ) ; return $ route ? $ this -> fromRoute ( $ route ) : $ this -> failedAction ( $ context ) ; }
Create Action from Context
30,059
protected function fromRoute ( Router \ Route $ route ) { return $ this -> newInstance ( $ route -> input , $ route -> domain , $ route -> responder ) ; }
Create an Action from a Route
30,060
protected function failedAction ( Context $ context ) { $ input = function ( ) use ( $ context ) { return [ $ context ] ; } ; return $ this -> newInstance ( $ input , [ $ this -> matcher , 'getName' ] , $ this -> failResponder ) ; }
Create an action for failed to match
30,061
public function initColVal ( $ columnsVal ) { $ this -> attributes [ 'columns' ] = array_keys ( $ columnsVal ) ; $ this -> attributes [ 'values' ] = array_values ( $ columnsVal ) ; }
init col and val to attributes
30,062
private function createAttributesQuery ( User $ user ) { $ query = $ this -> getEntityManager ( ) -> createQuery ( ' SELECT ua FROM UserBundle:UserAttribute ua LEFT JOIN ua.groups ug INDEX BY ua.id WHERE ug.id IN (:groupIds) ' ) -> setParameters ( [ ':groupIds' => $ user -> getGroupIds ( ) , ] ) ; return $ query ; }
Get list of user s attributes
30,063
public function initializeRoutingTable ( ) { $ routes = $ this -> routeObjectBackend -> loadObject ( ) ; if ( ! is_array ( $ routes ) ) { $ routes = array ( ) ; } $ this -> routes = $ routes ; }
Initializes the routing table . The function loads the saved routes from the object backend .
30,064
public function addRoute ( $ route , $ eventName , $ priority = 50 ) { if ( ! isset ( $ this -> routes [ $ priority ] ) ) { $ this -> routes [ $ priority ] = array ( ) ; ksort ( $ this -> routes ) ; } if ( isset ( $ this -> routes [ $ priority ] [ $ route ] ) ) { return true ; } $ this -> routes [ $ priority ] [ $ route ] = $ eventName ; $ this -> saveRoutes ( ) ; return true ; }
Adds an event handler for the given event .
30,065
public function removeRoute ( $ route , $ priority = 50 ) { if ( ! isset ( $ this -> routes [ $ priority ] ) ) { return true ; } if ( ! isset ( $ this -> routes [ $ priority ] [ $ route ] ) ) { return true ; } unset ( $ this -> routes [ $ priority ] [ $ route ] ) ; $ this -> saveRoutes ( ) ; return true ; }
Removes a route for the given priority .
30,066
public function clearCache ( $ reactivateModules = true ) { $ this -> routes = array ( ) ; if ( $ reactivateModules ) { $ this -> framework -> getModuleManager ( ) -> reactivateModules ( ) ; } }
Clears the route cache and reactivates the modules to rebuild the cache .
30,067
public function getEventNameForRoute ( RequestAbstract $ request ) { foreach ( $ this -> routes as $ priority => $ routes ) { foreach ( $ routes as $ route => $ eventName ) { $ result = $ this -> compareRoute ( $ route , $ request ) ; if ( $ result ) { return $ eventName ; } } } return false ; }
Returns the event name for the given request . The function uses the first possible match . The routes are sorted by the priority .
30,068
protected function compareRoute ( $ route , RequestAbstract $ request ) { $ route = str_replace ( '|' , $ request -> getRouteDelimiter ( ) , $ route ) ; $ routeParts = explode ( $ request -> getRouteDelimiter ( ) , $ route ) ; $ targetRouteParts = explode ( $ request -> getRouteDelimiter ( ) , trim ( $ request -> getRoute ( ) , $ request -> getRouteDelimiter ( ) ) ) ; $ numberOfTargetRouteParts = count ( $ targetRouteParts ) ; if ( count ( $ routeParts ) != $ numberOfTargetRouteParts ) { return false ; } $ routeParams = array ( ) ; $ routeIndex = 0 ; for ( $ pos = 0 ; $ pos < $ numberOfTargetRouteParts ; $ pos ++ ) { $ part = $ routeParts [ $ pos ] ; $ targetPart = $ targetRouteParts [ $ pos ] ; if ( $ targetPart != '' && preg_match ( '/\[(d|s)(?:\:([0-9a-zA-Z]*))?\]/' , $ part ) ) { list ( $ key , $ value ) = $ this -> parseRouteParam ( $ part , $ targetPart ) ; $ routeParams [ $ routeIndex ] = $ value ; $ routeIndex ++ ; if ( $ key !== '' ) { $ routeParams [ $ key ] = $ value ; } } else if ( $ part !== $ targetPart ) { return false ; } } $ request -> setRouteParams ( $ routeParams ) ; return true ; }
Compares the target route with the found route in the routing table .
30,069
protected function parseRouteParam ( $ part , $ targetPart ) { preg_match ( '/\[(d|s)(?:\:([0-9a-zA-Z]*))?\]/' , $ part , $ matches ) ; $ value = null ; if ( $ matches [ 1 ] === 'd' && is_numeric ( $ targetPart ) ) { $ value = $ targetPart * 1 ; } else if ( $ matches [ 1 ] === 's' && is_string ( $ targetPart ) ) { $ value = $ targetPart ; } $ key = '' ; if ( isset ( $ matches [ 2 ] ) ) { $ key = $ matches [ 2 ] ; } return [ $ key , $ value ] ; }
Parses the route param data to the correct format
30,070
public function setStatus ( $ status ) { if ( ! in_array ( $ status , array ( self :: STATUS_SUCCESS , self :: STATUS_ERROR , self :: STATUS_FAIL , ) ) ) { throw new Doozr_Base_Response_Rest_Exception ( ) ; } $ this -> status = $ status ; }
Setter for status .
30,071
public function from ( $ table ) { $ this -> fromTable = $ table ; $ this -> sql .= 'FROM ' . $ this -> quoteTableName ( $ table ) ; return $ this ; }
Generate a from statement .
30,072
public function where ( $ condition ) { $ this -> condition = $ condition ; $ this -> sql .= ' WHERE ' . $ this -> buildCondition ( $ condition ) ; return $ this ; }
Generate a where statement .
30,073
public function limit ( $ from , $ to = '' ) { $ this -> sql .= ' LIMIT ' . $ from ; if ( is_numeric ( $ to ) ) { $ this -> sql .= ', ' . $ to ; } return $ this ; }
Generate a limit statement .
30,074
public function update ( $ table , $ columns ) { $ this -> sql = 'UPDATE ' . $ this -> quoteTableName ( $ table ) . ' SET ' ; foreach ( $ columns as $ k => $ v ) { $ this -> sql .= $ this -> quoteColumnName ( $ k ) . ' = ' . $ this -> quoteValue ( $ v ) . ', ' ; } $ this -> sql = trim ( $ this -> sql , ', ' ) ; return $ this ; }
Generate an update statement .
30,075
private function buildCondition ( $ condition ) { $ where = '' ; foreach ( $ condition as $ filter ) { switch ( count ( $ filter ) ) { case 1 : $ where .= ' ' . $ this -> validateLogicalOperator ( ( $ filter [ 0 ] ) ) . ' ' ; break ; case 3 : $ where .= $ this -> quoteColumnName ( $ filter [ 1 ] ) . ' ' . $ this -> validateComparisonOperators ( $ filter [ 0 ] ) . ' ' . $ this -> handleThridParameter ( $ filter [ 2 ] ) ; break ; case 4 : $ where .= $ this -> quoteColumnName ( $ filter [ 1 ] ) . ' ' . $ this -> validateComparisonOperators ( $ filter [ 0 ] ) . ' ' . $ this -> quoteValue ( $ filter [ 2 ] ) . ' AND ' . $ this -> quoteValue ( $ filter [ 3 ] ) ; break ; } } return $ where ; }
Builds a where condition from the array parameter .
30,076
public function quoteColumnName ( $ column ) { if ( strpos ( $ column , '.' ) === false ) { return $ this -> quoteBacktick ( $ column ) ; } else { $ tokens = explode ( '.' , $ column ) ; $ numberOfTokens = count ( $ tokens ) ; if ( $ numberOfTokens == 2 ) { return $ this -> quoteBacktick ( $ tokens [ 0 ] ) . '.' . $ this -> quoteBacktick ( $ tokens [ 1 ] ) ; } else { throw new \ Exception ( "Columns name $column is not valid." ) ; } } }
Quotes column name using the backtick char .
30,077
private function handleThridParameter ( $ param ) { $ result = '' ; if ( is_array ( $ param ) ) { $ result = '(' ; foreach ( $ param as $ v ) { $ result .= $ this -> quoteValue ( $ v ) . ', ' ; } $ result = trim ( $ result , ', ' ) . ')' ; } else { $ result = $ this -> quoteValue ( $ param ) ; } return $ result ; }
Handles the thrid parameter in the condition array
30,078
private function validateLogicalOperator ( $ value ) { $ operator = strtoupper ( trim ( $ value ) ) ; $ isValid = in_array ( $ operator , $ this -> logicalOperators ) ; if ( $ isValid === true ) { return $ operator ; } throw new \ Exception ( "Logical operator $value is not supported." ) ; }
Validate if the logicalOperator is supported .
30,079
private function validateComparisonOperators ( $ value ) { $ operator = strtoupper ( trim ( $ value ) ) ; $ isValid = in_array ( $ operator , $ this -> comparisonOperators ) ; if ( $ isValid === true ) { return $ operator ; } throw new \ Exception ( "Comparison operator $value is not supported." ) ; }
Validate if the comparisonOperator is supported .
30,080
public function readRoutes ( ) { $ this -> __method = $ this -> detectMethod ( ) ; $ try_routes = array ( ) ; foreach ( $ this -> __routes as $ route ) { if ( substr ( $ route , 0 , strlen ( $ this -> __method ) ) == $ this -> __method ) { $ params = $ this -> routeParams ( $ route ) ; if ( $ params !== false && $ this -> hasParams ( $ params ) ) { if ( ! isset ( $ try_routes [ count ( $ params ) ] ) ) { $ try_routes [ count ( $ params ) ] = array ( ) ; } $ try_routes [ count ( $ params ) ] [ ] = $ route ; } elseif ( $ params === false ) { $ try_routes [ 0 ] = array ( $ route ) ; } } } $ num_params = array_keys ( $ try_routes ) ; rsort ( $ num_params ) ; $ this -> __route_stem = 'unknownRequest' ; if ( count ( $ num_params ) > 0 ) { $ longest = $ num_params [ 0 ] ; $ best_route = array_pop ( $ try_routes [ $ longest ] ) ; $ this -> __route_stem = $ this -> __method ; if ( $ longest > 0 ) { foreach ( $ this -> routeParams ( $ best_route ) as $ param ) { $ this -> $ param = $ this -> form -> $ param ; $ this -> __route_stem .= '_' . $ param ; } } } }
Parse request info and determine which route to use
30,081
static function CreateWithText ( $ path , $ text ) { $ dir = Path :: Directory ( $ path ) ; if ( ! Folder :: Exists ( $ dir ) ) Folder :: Create ( $ dir ) ; file_put_contents ( $ path , $ text ) ; }
Creates a file and puts the text in it ; if the file exists the content is overwritten .
30,082
static function GetContents ( $ path ) { if ( ! self :: Exists ( $ path ) ) throw new Exceptions \ PathNotFoundException ( "File $path doesn't exist" ) ; if ( ! self :: IsReadable ( $ path ) ) throw new Exceptions \ PathNoAccessException ( "File $path cannot be read" ) ; return file_get_contents ( $ path ) ; }
Reads all contents from a file into a string
30,083
static function GetMimeType ( $ path ) { if ( ! self :: IsReadable ( $ path ) ) throw new Exceptions \ PathNoAccessException ( "File $path cannot be read" ) ; $ finfo = \ finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime = @ \ finfo_file ( $ finfo , $ path ) ; if ( ! $ mime ) throw new \ Exception ( "File info of $path not readable" ) ; return $ mime ; }
Returns the mime type as string
30,084
static function GetLastModified ( $ path ) { $ ts = @ \ filemtime ( $ path ) ; if ( $ ts !== false ) return Date :: FromTimeStamp ( $ ts ) ; return null ; }
Gets the last modified date of the file or folder
30,085
static function Rename ( $ oldPath , $ newPath ) { if ( ! File :: Exists ( $ oldPath ) ) { throw new Exceptions \ PathNotFoundException ( "File $oldPath doesn't exist" ) ; } if ( Folder :: Exists ( $ newPath ) ) { throw new \ Exception ( "Target filename $newPath in use by a directory" ) ; } else if ( File :: Exists ( $ newPath ) ) { throw new \ Exception ( "Target file $newPath already exists" ) ; } if ( ! @ rename ( $ oldPath , $ newPath ) ) { throw new \ Exception ( "Error renaming file from $oldPath to $newPath" ) ; } }
Renames a file by changing its path
30,086
protected function setExceptionHandler ( $ class , string $ methodName = 'handleException' ) : Environment { if ( ! is_string ( $ class ) && ! is_object ( $ class ) ) { throw new \ InvalidArgumentException ( 'Given class must be a class name or a class instance.' ) ; } $ this -> exceptionHandler = [ 'class' => $ class , 'method' => $ methodName ] ; return $ this ; }
sets the exception handler to given class and method name
30,087
public function registerExceptionHandler ( string $ projectPath ) { if ( null === $ this -> exceptionHandler ) { return false ; } $ callback = $ this -> createCallback ( $ this -> exceptionHandler [ 'class' ] , $ this -> exceptionHandler [ 'method' ] , $ projectPath ) ; set_exception_handler ( $ callback ) ; return $ callback [ 0 ] ; }
registers exception handler for current mode
30,088
protected function setErrorHandler ( $ class , string $ methodName = 'handle' ) : Environment { if ( ! is_string ( $ class ) && ! is_object ( $ class ) ) { throw new \ InvalidArgumentException ( 'Given class must be a class name or a class instance.' ) ; } $ this -> errorHandler = [ 'class' => $ class , 'method' => $ methodName ] ; return $ this ; }
sets the error handler to given class and method name
30,089
public function registerErrorHandler ( string $ projectPath ) { if ( null === $ this -> errorHandler ) { return false ; } $ callback = $ this -> createCallback ( $ this -> errorHandler [ 'class' ] , $ this -> errorHandler [ 'method' ] , $ projectPath ) ; set_error_handler ( $ callback ) ; return $ callback [ 0 ] ; }
registers error handler for current mode
30,090
private function createCallback ( $ class , string $ methodName , string $ projectPath ) : callable { $ instance = ( ( is_string ( $ class ) ) ? ( new $ class ( $ projectPath ) ) : ( $ class ) ) ; return [ $ instance , $ methodName ] ; }
helper method to create the callback from the handler data
30,091
public function parseXML ( $ xml ) { $ document = new \ DOMDocument ( ) ; $ previousValue = libxml_use_internal_errors ( true ) ; libxml_clear_errors ( ) ; $ result = $ document -> loadXML ( $ xml ) ; $ errors = libxml_get_errors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ previousValue ) ; if ( true !== $ result ) { $ message = [ ] ; foreach ( $ errors as $ error ) { $ message [ ] = sprintf ( '%d. [%s] %s in on line %d in position %d' , count ( $ message ) + 1 , $ error -> code , str_replace ( [ "\n" , "\r" ] , '' , $ error -> message ) , $ error -> line , $ error -> column ) ; } throw new RuntimeException ( 'Can not parse XML: ' . implode ( '; ' , $ message ) ) ; } return $ this -> parseDocument ( $ document ) ; }
Parse XML and return Atom Document .
30,092
public function getMeta ( $ key = false , $ model = false ) { if ( $ key === false ) { return $ this -> meta ( ) -> get ( ) ; } if ( $ meta = $ this -> meta ( ) -> whereKey ( $ key ) -> first ( ) ) { return ( $ model == false ) ? $ meta -> value : $ meta ; } return false ; }
Helper function to return 1 meta model if key is set or returns the full results if not .
30,093
public static function memberOf ( $ file , $ exclude = 'plugins' ) { $ file = realpath ( $ file ) ; $ sep = DIRECTORY_SEPARATOR ; $ dirs = explode ( $ sep , $ file ) ; for ( $ i = 0 ; $ i < count ( $ dirs ) ; $ i ++ ) { if ( $ dirs [ $ i ] == $ exclude && isset ( $ dirs [ $ i + 1 ] ) ) { return $ dirs [ $ i + 1 ] ; } } return false ; }
Find the plugin containing a given file
30,094
public static function isEnabled ( $ plugin ) { $ plugin_list = static :: getPluginList ( ) ; return ( is_array ( $ plugin_list ) && in_array ( $ plugin , $ plugin_list ) ) ? true : false ; }
Check whether a given plugin is enabled
30,095
public static function pluginMap ( $ path = "" , $ carry = array ( ) ) { if ( $ path == '' ) { $ path = static :: defaultSearchDir ( ) ; } $ dir = opendir ( $ path ) ; while ( ( $ file = readdir ( $ dir ) ) !== false ) { if ( $ file [ 0 ] != '.' && $ file != 'noauto' && is_dir ( $ path . DIRECTORY_SEPARATOR . $ file ) ) { $ carry = self :: pluginMap ( $ path . DIRECTORY_SEPARATOR . $ file , $ carry ) ; } elseif ( substr ( $ file , - 4 ) == ".php" && ! in_array ( $ file , static :: $ unmapped_files ) ) { $ carry [ substr ( $ file , 0 , strlen ( $ file ) - 4 ) ] = realpath ( $ path . '/' . $ file ) ; } } closedir ( $ dir ) ; return $ carry ; }
Find potential class files in a given directory
30,096
public function actionIndex ( $ excludeFieldsPaginate = [ ] ) { if ( ! $ this -> _controller -> Components -> loaded ( 'Paginator' ) ) { $ this -> _controller -> Paginator = $ this -> _controller -> Components -> load ( 'Paginator' ) ; $ this -> _controller -> Paginator -> initialize ( $ this -> _controller ) ; } if ( ! $ this -> _controller -> Components -> loaded ( 'Filter' ) ) { $ this -> _controller -> Filter = $ this -> _controller -> Components -> load ( 'CakeTheme.Filter' ) ; $ this -> _controller -> Filter -> initialize ( $ this -> _controller ) ; } $ excludeFieldsPaginateDefault = [ 'department_id' ] ; $ excludeFieldsPaginateFull = array_unique ( array_merge ( $ excludeFieldsPaginateDefault , ( array ) $ excludeFieldsPaginate ) ) ; $ this -> _controller -> Paginator -> settings = $ this -> _modelEmployee -> getPaginateOptions ( $ excludeFieldsPaginateFull ) ; $ conditions = $ this -> _controller -> Filter -> getFilterConditions ( ) ; $ employees = $ this -> _controller -> Paginator -> paginate ( 'Employee' , $ conditions ) ; if ( empty ( $ employees ) ) { $ this -> _controller -> Flash -> information ( __d ( 'cake_ldap' , 'Employees not found' ) ) ; } $ filterOptions = $ this -> _modelEmployee -> getFilterOptions ( ) ; $ fieldsConfig = $ this -> _modelEmployee -> getFieldsConfig ( ) ; $ isTreeReady = $ this -> _modelConfigSync -> getFlagTreeSubordinateEnable ( ) ; $ pageHeader = __d ( 'cake_ldap' , 'Index of employees' ) ; $ headerMenuActions = [ [ 'fas fa-sync-alt' , __d ( 'cake_ldap' , 'Synchronize information with LDAP server' ) , [ 'controller' => 'employees' , 'action' => 'sync' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Synchronize information of employees with LDAP server' ) , 'data-toggle' => 'request-only' , ] ] ] ; if ( $ isTreeReady ) { $ headerMenuActions [ ] = [ 'fas fa-sitemap' , __d ( 'cake_ldap' , 'Tree of employees' ) , [ 'controller' => 'employees' , 'action' => 'tree' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Tree view of employees' ) ] ] ; } $ breadCrumbs = $ this -> _modelEmployee -> getBreadcrumbInfo ( ) ; $ breadCrumbs [ ] = __d ( 'cake_ldap' , 'Index' ) ; $ this -> _controller -> ViewExtension -> setRedirectUrl ( true , 'employee' ) ; $ this -> _controller -> set ( compact ( 'employees' , 'filterOptions' , 'fieldsConfig' , 'isTreeReady' , 'pageHeader' , 'headerMenuActions' , 'breadCrumbs' ) ) ; }
Action index . Used to view a complete list of employees .
30,097
public function actionSync ( $ guid = null , $ useQueue = true ) { if ( empty ( $ guid ) || $ useQueue ) { $ modelQueuedTask = ClassRegistry :: init ( 'Queue.QueuedTask' ) ; $ data = null ; if ( ! empty ( $ guid ) ) { $ data = compact ( 'guid' ) ; } if ( ( bool ) $ modelQueuedTask -> createJob ( 'SyncEmployee' , $ data , null , 'sync' ) ) { $ this -> _controller -> Flash -> success ( __d ( 'cake_ldap' , 'Synchronization information of employees put in queue...' ) ) ; $ this -> _controller -> ViewExtension -> setProgressSseTask ( 'SyncEmployee' ) ; } else { $ this -> _controller -> Flash -> error ( __d ( 'cake_ldap' , 'Synchronization information of employees put in queue unsuccessfully' ) ) ; } } else { $ modelSync = ClassRegistry :: init ( 'CakeLdap.Sync' ) ; if ( $ modelSync -> syncInformation ( $ guid ) ) { $ this -> _controller -> Flash -> success ( __d ( 'cake_ldap' , 'Synchronization information of employees has been finished successfully' ) ) ; } else { $ this -> _controller -> Flash -> error ( __d ( 'cake_ldap' , 'Synchronization information of employees has been finished unsuccessfully' ) ) ; } } $ this -> _controller -> ViewExtension -> setRedirectUrl ( null , 'employee' ) ; return $ this -> _controller -> ViewExtension -> redirectByUrl ( null , 'employee' ) ; }
Action sync . Used to synchronization information of employee with Active Directory .
30,098
public function actionTree ( $ id = null , $ includeBlocked = false , $ includeFields = null ) { if ( ! $ this -> _modelConfigSync -> getFlagTreeSubordinateEnable ( ) ) { throw new InternalErrorException ( __d ( 'cake_ldap' , 'The database does not contain information on the tree view' ) ) ; } $ fieldsDb = $ this -> _modelConfigSync -> getListFieldsDb ( ) ; $ excludeFields = [ CAKE_LDAP_LDAP_ATTRIBUTE_OTHER_TELEPHONE_NUMBER , CAKE_LDAP_LDAP_ATTRIBUTE_OTHER_MOBILE_TELEPHONE_NUMBER , ] ; $ fieldsList = [ 'id' , 'block' , CAKE_LDAP_LDAP_ATTRIBUTE_NAME , CAKE_LDAP_LDAP_ATTRIBUTE_TITLE ] ; if ( ! empty ( $ id ) && ! $ this -> _modelEmployee -> exists ( $ id ) ) { return $ this -> _controller -> ViewExtension -> setExceptionMessage ( new NotFoundException ( __d ( 'cake_ldap' , 'Invalid ID for employee' ) ) ) ; } if ( $ this -> _controller -> Components -> loaded ( 'ViewExtension' ) ) { $ this -> _controller -> ViewExtension -> setRedirectUrl ( true , 'employee' ) ; } $ employees = $ this -> _modelSubordinate -> getArrayTreeEmployee ( $ id , true , $ includeBlocked , $ includeFields ) ; $ isTreeDraggable = $ this -> _modelConfigSync -> getFlagTreeSubordinateDraggable ( ) ; $ expandAll = ! empty ( $ id ) ; $ pageHeader = __d ( 'cake_ldap' , 'Tree view information of employees' ) ; $ headerMenuActions = [ [ 'fas fa-sync-alt' , __d ( 'cake_ldap' , 'Synchronize information with LDAP server' ) , [ 'controller' => 'employees' , 'action' => 'sync' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Synchronize information of employees with LDAP server' ) , 'data-toggle' => 'request-only' , ] ] , [ 'fas fa-sort-alpha-down' , __d ( 'cake_ldap' , 'Order tree of employees' ) , [ 'controller' => 'employees' , 'action' => 'order' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Order tree of employees by alphabet' ) , 'action-type' => 'confirm-post' , 'data-confirm-msg' => __d ( 'cake_ldap' , 'Are you sure you wish to re-order tree of employees?' ) ] ] , [ 'fas fa-check' , __d ( 'cake_ldap' , 'Check state tree of employees' ) , [ 'controller' => 'employees' , 'action' => 'check' , 'prefix' => false ] , [ 'title' => __d ( 'cake_ldap' , 'Check state tree of employees' ) ] ] ] ; $ breadCrumbs = $ this -> _modelEmployee -> getBreadcrumbInfo ( ) ; $ breadCrumbs [ ] = __d ( 'cake_ldap' , 'Tree viewing' ) ; $ this -> _controller -> set ( compact ( 'employees' , 'isTreeDraggable' , 'expandAll' , 'pageHeader' , 'headerMenuActions' , 'breadCrumbs' ) ) ; }
Action tree . Used to view tree of subordinate employees .
30,099
public function actionOrder ( ) { if ( ! $ this -> _modelConfigSync -> getFlagTreeSubordinateEnable ( ) ) { throw new InternalErrorException ( __d ( 'cake_ldap' , 'The database does not contain information on the tree view' ) ) ; } $ this -> _controller -> request -> allowMethod ( 'post' ) ; $ modelQueuedTask = ClassRegistry :: init ( 'Queue.QueuedTask' ) ; if ( ( bool ) $ modelQueuedTask -> createJob ( 'OrderEmployee' , null , null , 'order' ) ) { $ this -> _controller -> Flash -> success ( __d ( 'cake_ldap' , 'Order tree of employees put in queue...' ) ) ; $ this -> _controller -> ViewExtension -> setProgressSseTask ( 'OrderEmployee' ) ; } else { $ this -> _controller -> Flash -> error ( __d ( 'cake_ldap' , 'Order tree of employees put in queue unsuccessfully' ) ) ; } $ redirectUrl = [ 'controller' => 'employees' , 'action' => 'tree' ] ; return $ this -> _controller -> redirect ( $ redirectUrl ) ; }
Action order . Used to reorder tree of subordinate employees .