idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
57,300
|
private function injectRenderer ( array $ config , Mustache $ mustache , ContainerInterface $ container ) { if ( isset ( $ config [ 'renderer' ] ) ) { if ( is_string ( $ config [ 'renderer' ] ) && $ container -> has ( $ config [ 'renderer' ] ) ) { $ mustache -> setRenderer ( $ container -> get ( $ config [ 'renderer' ] ) ) ; return ; } if ( $ config [ 'renderer' ] instanceof Renderer ) { $ mustache -> setRenderer ( $ config [ 'renderer' ] ) ; } if ( is_string ( $ config [ 'renderer' ] ) && class_exists ( $ config [ 'renderer' ] ) ) { $ mustache -> setRenderer ( new $ config [ 'renderer' ] ( ) ) ; } } if ( ! isset ( $ config [ 'escaper' ] ) ) { return ; } if ( $ config [ 'escaper' ] instanceof Escaper ) { $ mustache -> getRenderer ( ) -> setEscaper ( $ config [ 'escaper' ] ) ; return ; } if ( ! is_string ( $ config [ 'escaper' ] ) ) { return ; } if ( $ container -> has ( $ config [ 'escaper' ] ) ) { $ mustache -> getRenderer ( ) -> setEscaper ( $ container -> get ( $ config [ 'escaper' ] ) ) ; return ; } if ( class_exists ( $ config [ 'escaper' ] ) ) { $ mustache -> getRenderer ( ) -> setEscaper ( new $ config [ 'escaper' ] ( ) ) ; return ; } }
|
Inject the renderer if needed and potentially the escaper .
|
57,301
|
private function injectUriHelper ( MustacheTemplate $ renderer , ContainerInterface $ container ) { if ( ! $ container -> has ( UrlHelper :: class ) ) { return ; } $ renderer -> addDefaultParam ( $ renderer :: TEMPLATE_ALL , 'uri' , new UriHelper ( $ container -> get ( UrlHelper :: class ) ) ) ; }
|
Inject the renderer instance with a UriHelper helper if possible .
|
57,302
|
public function setServiceList ( $ serviceList = [ ] ) { if ( ! $ serviceList ) return ; foreach ( $ serviceList as $ key => $ closure ) { $ this -> set ( $ key , $ closure ) ; } }
|
sets services to the closure factory
|
57,303
|
protected function workout ( FormInterface $ form ) { foreach ( self :: $ workers as $ worker ) { call_user_func_array ( [ $ worker , 'execute' ] , [ $ form , $ this -> parsedData ] ) ; } }
|
Updates the form with definitions from parsed data
|
57,304
|
protected function createForm ( ) { $ class = self :: DEFAULT_FORM_CLASS ; if ( array_key_exists ( 'class' , $ this -> parsedData ) ) { $ class = $ this -> checkClass ( $ this -> parsedData [ 'class' ] ) ; } return new $ class ; }
|
Creates the form class
|
57,305
|
static public function htmlClassTr ( $ html , $ css_tr ) { $ html = preg_replace_callback ( '@<(?<tag>[a-z]+)(?<other>\s+[^>]*)class="(?<class>[^"]+)"@s' , function ( $ attrs ) use ( $ css_tr ) { $ class = ' ' . strtr ( $ attrs [ 'class' ] , array ( "\n" => ' ' , "\r" => ' ' , "\t" => ' ' , ) ) . ' ' ; $ class = strtr ( $ class , $ css_tr [ '*' ] ) ; if ( isset ( $ css_tr [ $ attrs [ 'tag' ] ] ) ) { $ class = strtr ( $ class , $ css_tr [ $ attrs [ 'tag' ] ] ) ; } $ class = trim ( $ class ) ; if ( $ class !== '' ) { $ class = 'class="' . $ class . '"' ; } return '<' . $ attrs [ 'tag' ] . $ attrs [ 'other' ] . $ class ; } , $ html ) ; return $ html ; }
|
Translate css classes .
|
57,306
|
public function handle ( ) { if ( \ Skeleton \ Core \ Hook :: exists ( 'handle_error' , [ $ this -> exception ] ) ) { $ this -> last_handler = true ; \ Skeleton \ Core \ Hook :: call ( 'handle_error' , [ $ this -> exception ] ) ; } }
|
Handle the exception with a hook in the current application
|
57,307
|
public function can_run ( ) { if ( class_exists ( '\\Skeleton\\Core\\Application' ) === false ) { return false ; } try { \ Skeleton \ Core \ Application :: get ( ) ; return true ; } catch ( \ Exception $ e ) { } ; return false ; }
|
Can this handler run?
|
57,308
|
public function compose ( $ name = null , $ options = array ( ) ) { $ menu = app ( 'antares.widget' ) -> make ( 'menu.translations.pane' ) ; $ areas = config ( 'areas.areas' ) ; $ area = request ( ) -> segment ( 4 ) ; foreach ( $ areas as $ name => $ title ) { $ menu -> add ( $ name ) -> link ( handles ( 'antares::translations/index/' . $ name ) ) -> title ( trans ( $ title ) ) -> icon ( 'zmdi-accounts' ) -> active ( $ area == $ name ) ; } app ( 'antares.widget' ) -> make ( 'pane.left' ) -> add ( 'translations' ) -> content ( view ( 'antares/translations::admin.partials._left_pane' ) ) ; }
|
panel left for translations
|
57,309
|
public function setInsideTemplateDirectory ( $ inside ) { $ this -> insideTemplateDirectory = $ inside ; $ this -> getPathManager ( ) -> getGenerator ( ) -> setInsideTemplateDirectory ( $ inside ) ; }
|
Sets whether or not the engine is running inside a _template directory .
|
57,310
|
public function generateContent ( $ destination ) { $ pathsWrittenTo = [ ] ; $ packageStructure = $ this -> pathManager -> emitStructure ( $ destination ) ; $ this -> getRenderer ( ) -> addCollector ( $ this -> getPathManager ( ) -> getCollector ( ) ) ; $ this -> getRenderer ( ) -> addCollector ( app ( InputCollector :: class ) ) ; $ this -> pathManager -> getRenderer ( ) -> setIgnoreUnloadedTemplateErrors ( true ) ; foreach ( $ packageStructure as $ packageFile ) { if ( $ this -> fileSystem -> exists ( $ packageFile [ 'full' ] ) ) { if ( ! $ this -> shouldCopyFileInstead ( $ packageFile [ 'original' ] ) ) { $ packageFileContents = $ this -> pathManager -> getRenderer ( ) -> render ( $ packageFile [ 'original' ] ) ; if ( $ packageFileContents != null && strlen ( $ packageFileContents ) > 0 ) { $ this -> fileSystem -> put ( $ packageFile [ 'full' ] , $ packageFileContents ) ; $ pathsWrittenTo [ ] = $ packageFile ; } } else { $ this -> fileSystem -> copy ( $ packageFile [ 'origin' ] , $ packageFile [ 'full' ] ) ; } } } $ this -> pathManager -> getRenderer ( ) -> setIgnoreUnloadedTemplateErrors ( false ) ; return $ pathsWrittenTo ; }
|
Generates files and contents in the provided destination directory .
|
57,311
|
private function isExcludedFromVerbatim ( $ file ) { foreach ( $ this -> copyVerbatimExcludePatterns as $ pattern ) { if ( Str :: is ( $ pattern , $ file ) ) { return true ; } } return false ; }
|
Determines if a file should be excluded copying .
|
57,312
|
private function shouldCopyFileInstead ( $ file ) { if ( $ this -> isExcludedFromVerbatim ( $ file ) ) { return false ; } foreach ( $ this -> copyVerbatimPatterns as $ pattern ) { if ( Str :: is ( $ pattern , $ file ) ) { return true ; } } return false ; }
|
Determines if a file should simply be copied .
|
57,313
|
protected static function requireValue ( $ data , $ key ) { if ( isset ( $ data [ $ key ] ) ) { return $ data [ $ key ] ; } else { throw new Exception \ InvalidDataException ( "Required value for '$key' is missing" ) ; } }
|
Requires a value from the given array or throws InvalidDataException
|
57,314
|
public function loadView ( ezcMvcRoutingInformation $ routeInfo , ezcMvcRequest $ request , ezcMvcResult $ result ) { if ( $ routeInfo -> controllerClass === 'ezpRestAtomController' ) { return new ezpRestAtomView ( $ request , $ result ) ; } return new ezpRestJsonView ( $ request , $ result ) ; }
|
Creates a view required by controller s result
|
57,315
|
protected function end ( ) : void { if ( ( $ this -> options & self :: OUTPUT_LINES ) === 0 ) { fwrite ( $ this -> stream , ( isset ( $ this -> delimiter ) ? "\n" : '' ) . ']' ) ; } }
|
End writing to the stream .
|
57,316
|
protected function jsonEncode ( $ element ) : string { $ json = json_encode ( $ element , $ this -> options ) ; if ( $ json === false ) { trigger_error ( "JSON encode failed; " . json_last_error_msg ( ) , E_USER_WARNING ) ; return json_encode ( null ) ; } if ( ( $ this -> options & \ JSON_PRETTY_PRINT ) > 0 && ( ~ $ this -> options & self :: OUTPUT_LINES ) > 0 ) { $ json = rtrim ( " " . str_replace ( "\n" , "\n " , $ json ) ) ; } return $ json ; }
|
JSON encode an element with error checking
|
57,317
|
public function getChanContents ( int $ channel = 1 ) : string { if ( ! isset ( $ this -> pipes [ $ channel ] ) ) throw new \ InvalidArgumentException ( "No channel '$channel' defined." ) ; return $ this -> pipes [ $ channel ] ; }
|
Get the contents of a channel
|
57,318
|
private function loadConfig ( $ config ) { if ( isset ( $ config [ 'moduleConf' ] [ 'API_USERNAME' ] ) && isset ( $ config [ 'moduleConf' ] [ 'API_PASSWORD' ] ) && isset ( $ config [ 'moduleConf' ] [ 'API_SIGNATURE' ] ) && isset ( $ config [ 'moduleConf' ] [ 'API_ENDPOINT' ] ) && isset ( $ config [ 'moduleConf' ] [ 'version' ] ) && isset ( $ config [ 'moduleConf' ] [ 'paypal_url' ] ) && isset ( $ config [ 'moduleConf' ] [ 'command_url' ] ) ) { $ this -> setAPI_USERNAME ( $ config [ 'moduleConf' ] [ 'API_USERNAME' ] ) ; $ this -> setAPI_PASSWORD ( $ config [ 'moduleConf' ] [ 'API_PASSWORD' ] ) ; $ this -> setAPI_SIGNATURE ( $ config [ 'moduleConf' ] [ 'API_SIGNATURE' ] ) ; $ this -> setAPI_ENDPOINT ( $ config [ 'moduleConf' ] [ 'API_ENDPOINT' ] ) ; $ this -> setVersion ( $ config [ 'moduleConf' ] [ 'version' ] ) ; $ this -> setPaypal_url ( $ config [ 'moduleConf' ] [ 'paypal_url' ] ) ; $ this -> setCommand_url ( $ config [ 'moduleConf' ] [ 'command_url' ] ) ; } else { throw new PaypalException ( 'Missing values in config file.' ) ; } }
|
Reads parsed config file and sets needed attributes
|
57,319
|
function deformatNVP ( $ nvpstr ) { $ intial = 0 ; $ nvpArray = array ( ) ; while ( strlen ( $ nvpstr ) ) { $ keypos = strpos ( $ nvpstr , '=' ) ; $ valuepos = strpos ( $ nvpstr , '&' ) ? strpos ( $ nvpstr , '&' ) : strlen ( $ nvpstr ) ; $ keyval = substr ( $ nvpstr , $ intial , $ keypos ) ; $ valval = substr ( $ nvpstr , $ keypos + 1 , $ valuepos - $ keypos - 1 ) ; $ nvpArray [ urldecode ( $ keyval ) ] = urldecode ( $ valval ) ; $ nvpstr = substr ( $ nvpstr , $ valuepos + 1 , strlen ( $ nvpstr ) ) ; } return $ nvpArray ; }
|
This function will take NVPString and convert it to an Associative Array and it will decode the response . It is usefull to search for a particular key and displaying arrays .
|
57,320
|
protected function _make ( $ config ) { try { $ data = $ this -> _containerGet ( $ config , MapFactoryInterface :: K_DATA ) ; } catch ( ContainerExceptionInterface $ e ) { throw $ this -> _createRuntimeException ( $ this -> __ ( 'Could not retrieve data from factory config' ) , null , $ e ) ; } try { $ data = $ this -> _normalizeIterable ( $ data ) ; } catch ( InvalidArgumentException $ e ) { throw $ this -> _createRuntimeException ( $ this -> __ ( 'Map data must be iterable' ) , null , $ e ) ; } $ map = new stdClass ( ) ; foreach ( $ data as $ _key => $ _value ) { try { $ map -> { $ _key } = $ this -> _normalizeChild ( $ _value , $ config ) ; } catch ( InvalidArgumentException $ e ) { throw $ this -> _createRuntimeException ( $ this -> __ ( 'Element "%1$s" is invalid' , [ $ _key ] ) , null , $ e ) ; } } $ product = $ this -> _createProduct ( $ config , $ map ) ; return $ product ; }
|
Creates a map with the given data .
|
57,321
|
public static function alternator ( ) { $ args = func_get_args ( ) ; return function ( $ next = true ) use ( $ args ) { static $ i = 0 ; return $ args [ ( $ next ? $ i ++ : $ i ) % count ( $ args ) ] ; } ; }
|
Returns a closure that will alternate between the args which to return . If you call the closure with false as the arg it will return the value without alternating the next time .
|
57,322
|
public static function is_xml ( $ string ) { if ( ! defined ( 'LIBXML_COMPACT' ) ) { throw new \ Exception ( 'libxml is required to use Str::is_xml()' ) ; } $ internal_errors = libxml_use_internal_errors ( ) ; libxml_use_internal_errors ( true ) ; $ result = simplexml_load_string ( $ string ) !== false ; libxml_use_internal_errors ( $ internal_errors ) ; return $ result ; }
|
Check if a string is a valid XML
|
57,323
|
public function clear ( ) { foreach ( array_keys ( $ this -> instances ) as $ key ) { $ this -> instances [ $ key ] = null ; unset ( $ this -> instances [ $ key ] ) ; } $ this -> instances = [ ] ; }
|
Unsets and removes all cached Hydrator instances
|
57,324
|
public function createSideMenu ( ) { $ this -> pool -> prepare ( ) ; $ menu = $ this -> factory -> createItem ( 'root' , [ 'childrenAttributes' => [ 'id' => 'sidebar-menu' ] ] ) ; $ menu -> addChild ( 'dashboard' , [ 'route' => 'ekyna_admin_dashboard' , 'labelAttributes' => [ 'icon' => 'dashboard' ] , ] ) -> setLabel ( 'ekyna_admin.dashboard' ) ; $ this -> appendChildren ( $ menu ) ; return $ menu ; }
|
Builds backend sidebar menu .
|
57,325
|
private function appendChildren ( ItemInterface $ menu ) { foreach ( $ this -> pool -> getGroups ( ) as $ group ) { $ groupOptions = [ 'labelAttributes' => [ 'icon' => $ group -> getIcon ( ) ] , 'childrenAttributes' => [ 'class' => 'submenu' ] ] ; if ( $ group -> hasEntries ( ) ) { $ groupOptions [ 'labelAttributes' ] [ 'class' ] = 'dropdown-toggle' ; $ groupEntries = [ ] ; foreach ( $ group -> getEntries ( ) as $ entry ) { if ( ! $ this -> entrySecurityCheck ( $ entry ) ) { continue ; } $ groupEntry = $ this -> factory -> createItem ( $ entry -> getName ( ) , [ 'route' => $ entry -> getRoute ( ) ] ) ; $ groupEntry -> setLabel ( $ entry -> getLabel ( ) ) -> setExtra ( 'translation_domain' , $ entry -> getDomain ( ) ) ; $ groupEntries [ ] = $ groupEntry ; } if ( 0 < count ( $ groupEntries ) ) { $ menuGroup = $ menu -> addChild ( $ group -> getName ( ) , $ groupOptions ) -> setLabel ( $ group -> getLabel ( ) ) -> setExtra ( 'translation_domain' , $ group -> getDomain ( ) ) ; foreach ( $ groupEntries as $ groupEntry ) { $ menuGroup -> addChild ( $ groupEntry ) ; } } } else { $ groupOptions [ 'route' ] = $ group -> getRoute ( ) ; $ menu -> addChild ( $ group -> getName ( ) , $ groupOptions ) -> setLabel ( $ group -> getLabel ( ) ) -> setExtra ( 'translation_domain' , $ group -> getDomain ( ) ) ; } } }
|
Fills the menu with menu pool s groups and entries .
|
57,326
|
private function entrySecurityCheck ( MenuEntry $ entry ) { if ( null !== $ resource = $ entry -> getResource ( ) ) { return $ this -> aclOperator -> isAccessGranted ( $ resource , 'VIEW' ) ; } return true ; }
|
Returns whether the user has access granted for the given entry .
|
57,327
|
public function breadcrumbAppend ( $ name , $ label , $ route = null , array $ parameters = [ ] ) { $ this -> createBreadcrumb ( ) ; $ this -> breadcrumb -> addChild ( $ name , [ 'route' => $ route , 'routeParameters' => $ parameters ] ) -> setLabel ( $ label ) ; }
|
Appends a breadcrumb element .
|
57,328
|
public function setImmutable ( $ immutable = true ) { if ( $ immutable ) { $ this -> headers -> addCacheControlDirective ( 'immutable' ) ; } else { $ this -> headers -> removeCacheControlDirective ( 'immutable' ) ; } return $ this ; }
|
Marks the response as immutable .
|
57,329
|
public function run ( ) { if ( $ this -> binding instanceof \ Closure ) { return call_user_func_array ( $ this -> binding , $ this -> parameters ) ; } if ( is_object ( $ this -> binding ) ) { return $ this -> binding ; } if ( is_string ( $ this -> binding ) ) { return null ; } return $ this -> binding ; }
|
Run the builder create the binding s instance and return it
|
57,330
|
protected function mx_query ( $ domain ) { $ hosts = array ( ) ; $ weight = array ( ) ; if ( function_exists ( 'getmxrr' ) ) { getmxrr ( $ domain , $ hosts , $ weight ) ; } else { $ this -> getmxrr ( $ domain , $ hosts , $ weight ) ; } return array ( $ hosts , $ weight ) ; }
|
Queries the DNS server for MX entries of a certain domain .
|
57,331
|
protected function getmxrr ( $ hostname , & $ mxhosts , & $ mxweights ) { if ( ! Arrays :: is ( $ mxhosts ) ) { $ mxhosts = array ( ) ; } if ( ! Arrays :: is ( $ mxweights ) ) { $ mxweights = array ( ) ; } if ( empty ( $ hostname ) ) { return ; } $ cmd = 'nslookup -type=MX ' . escapeshellarg ( $ hostname ) ; if ( ! empty ( $ this -> mx_query_ns ) ) { $ cmd .= ' ' . escapeshellarg ( $ this -> mx_query_ns ) ; } exec ( $ cmd , $ output ) ; if ( empty ( $ output ) ) { return ; } $ i = - 1 ; foreach ( $ output as $ line ) { $ i ++ ; if ( preg_match ( "/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i" , $ line , $ parts ) ) { $ mxweights [ $ i ] = trim ( $ parts [ 1 ] ) ; $ mxhosts [ $ i ] = trim ( $ parts [ 2 ] ) ; } if ( preg_match ( '/responsible mail addr = (.+)$/i' , $ line , $ parts ) ) { $ mxweights [ $ i ] = $ i ; $ mxhosts [ $ i ] = trim ( $ parts [ 1 ] ) ; } } return ( $ i != - 1 ) ; }
|
Provides a windows replacement for the getmxrr function . Params and behaviour is that of the regular getmxrr function .
|
57,332
|
public function add ( $ key , $ value ) { if ( empty ( $ key ) ) return false ; if ( empty ( $ this -> engineVarList -> $ key ) ) { $ this -> engineVarList -> $ key = $ value ; return $ this ; } if ( is_array ( $ this -> engineVarList -> $ key ) ) { array_merge ( $ this -> engineVarList -> $ key , $ value ) ; } return $ this ; }
|
just adds a variable to the others
|
57,333
|
public function initialize ( $ dataSource ) { $ this -> position = 0 ; $ this -> count = null ; if ( is_array ( $ dataSource ) ) { reset ( $ dataSource ) ; $ this -> dataSource = new ArrayIterator ( $ dataSource ) ; } elseif ( $ dataSource instanceof IteratorAggregate ) { $ this -> dataSource = $ dataSource -> getIterator ( ) ; $ this -> dataSource -> rewind ( ) ; } elseif ( $ dataSource instanceof Iterator ) { $ this -> dataSource = $ dataSource ; $ this -> dataSource -> rewind ( ) ; } else { throw new Exception \ InvalidArgumentException ( 'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate' ) ; } return $ this ; }
|
Set the data source for the result set
|
57,334
|
protected function itemToArray ( $ item ) { if ( is_array ( $ item ) ) { return $ item ; } elseif ( method_exists ( $ item , 'toArray' ) ) { return $ item -> toArray ( ) ; } elseif ( method_exists ( $ item , 'getArrayCopy' ) ) { return $ item -> getArrayCopy ( ) ; } throw new Exception \ RuntimeException ( sprintf ( 'Items as part of this DataSource, with type "%s" cannot be cast to an array' , is_object ( $ item ) ? get_class ( $ item ) : gettype ( $ item ) ) ) ; }
|
Cast an item to array
|
57,335
|
public function getConfigs ( $ className ) { if ( \ is_object ( $ className ) ) { $ className = ClassUtils :: getClass ( $ className ) ; } if ( ! array_key_exists ( $ className , $ this -> configs ) ) { $ this -> configs [ $ className ] = [ [ ] , [ ] ] ; $ meta = $ this -> om -> getClassMetadata ( $ className ) ; $ this -> addConfigFields ( $ meta , $ className ) ; $ this -> addConfigAssociations ( $ meta , $ className ) ; } return $ this -> configs [ $ className ] ; }
|
Get the object configs .
|
57,336
|
public function injectFieldOptions ( InputDefinition $ definition , $ className ) { list ( $ fields , $ associations ) = $ this -> getConfigs ( $ className ) ; ObjectFieldUtil :: addOptions ( $ definition , $ fields , 'The <comment>"%s"</comment> field' ) ; ObjectFieldUtil :: addOptions ( $ definition , $ associations , 'The <comment>"%s"</comment> association identifier of <comment>"%s"</comment>' ) ; }
|
Inject the fields options in command definition .
|
57,337
|
public function injectNewValues ( InputInterface $ input , $ instance , $ targetId = 'id' ) { list ( $ fields , $ associations ) = $ this -> getConfigs ( $ instance ) ; $ fieldNames = array_keys ( array_merge ( $ fields , $ associations ) ) ; foreach ( $ fieldNames as $ fieldName ) { $ value = ObjectFieldUtil :: getFieldValue ( $ input , $ fieldName ) ; if ( empty ( $ value ) ) { continue ; } $ value = ObjectFieldUtil :: convertEmptyValue ( $ value ) ; if ( ( array_key_exists ( $ fieldName , $ fields ) ) ) { ObjectFieldUtil :: setFieldValue ( $ instance , $ fieldName , $ value ) ; } elseif ( ( array_key_exists ( $ fieldName , $ associations ) ) ) { $ this -> setAssociationValue ( $ instance , $ fieldName , $ value , $ associations [ $ fieldName ] , $ targetId ) ; } } }
|
Inject the field values in the object instance .
|
57,338
|
private function setAssociationValue ( $ instance , $ fieldName , $ value , $ target , $ id ) { $ targetRepo = $ this -> om -> getRepository ( $ target ) ; $ target = $ targetRepo -> findBy ( [ $ id => $ value ] ) ; if ( null === $ target ) { throw new \ InvalidArgumentException ( sprintf ( 'The specified mapped field "%s" couldn\'t be found with the Id "%s".' , $ fieldName , $ value ) ) ; } ObjectFieldUtil :: setFieldValue ( $ instance , $ fieldName , $ target [ 0 ] ) ; }
|
Set the association field value .
|
57,339
|
private function addConfigFields ( ClassMetadata $ metadata , $ className ) { foreach ( $ metadata -> getFieldNames ( ) as $ field ) { if ( ! $ metadata -> isIdentifier ( $ field ) ) { $ this -> configs [ $ className ] [ 0 ] [ $ field ] = $ metadata -> getTypeOfField ( $ field ) ; } } }
|
Add the config of fields .
|
57,340
|
private function addConfigAssociations ( ClassMetadata $ metadata , $ className ) { foreach ( $ metadata -> getAssociationNames ( ) as $ association ) { if ( ! $ metadata -> isAssociationInverseSide ( $ association ) && $ metadata -> isSingleValuedAssociation ( $ association ) ) { $ this -> configs [ $ className ] [ 1 ] [ $ association ] = $ metadata -> getAssociationTargetClass ( $ association ) ; } } }
|
Add the config of associations .
|
57,341
|
public function Run ( $ displayView = TRUE ) { if ( ! $ this -> urlProcessor ) { $ this -> urlProcessor = new Resource \ Controller \ URL \ Route ; } $ this -> urlProcessor -> Process ( ) ; $ controllerPaths = is_array ( $ this -> controllerPath ) ? $ this -> controllerPath : [ $ this -> controllerPath ] ; foreach ( $ controllerPaths as $ controllerClass ) { $ controllerClass .= $ this -> controllerModule ? '\\' . $ this -> controllerModule : NULL ; if ( $ this -> urlProcessor -> findController ( $ controllerClass , $ this -> captureall ) ) { break ; } } if ( ! class_exists ( $ this -> urlProcessor -> controller ) || ! method_exists ( $ this -> urlProcessor -> controller , $ this -> urlProcessor -> action ) ) { throw new Exception ( 'Invalid controller action: ' . $ this -> urlProcessor -> controller . '\\' . $ this -> urlProcessor -> action , 404 ) ; } $ controllerObj = $ this -> urlProcessor -> createController ( $ controllerClass ) ; if ( $ this -> controllerModule ) { $ controllerObj -> module = $ this -> controllerModule ; } if ( $ this -> view && ! $ controllerObj -> view ) { $ controllerObj -> view = $ this -> view ; } if ( $ this -> useExceptionHandler ) { set_exception_handler ( array ( $ controllerObj , 'Exception' ) ) ; } if ( is_callable ( array ( $ controllerObj , $ controllerObj -> action ) ) && $ controllerObj -> isActionValid ( ) ) { $ controllerObj -> callAction ( ) ; } else { throw new Exception ( 'Invalid controller action: ' . $ controllerObj -> controller . '\\' . $ controllerObj -> action , 404 ) ; } if ( $ displayView && $ controllerObj -> render ) { $ controllerObj -> View ( ) ; } return $ controllerObj ; }
|
Determine the controller and run the action
|
57,342
|
public static function failedToDecodeResponse ( ResponseInterface $ response , $ error ) { $ response -> getBody ( ) -> rewind ( ) ; return new static ( sprintf ( "Failed to decode response '%s' with error '%s'" , $ response -> getBody ( ) -> getContents ( ) , $ error ) ) ; }
|
Thrown when an response could not be JSON decoded .
|
57,343
|
public static function invalidResponseBody ( ResponseInterface $ response , $ expectedPath ) { $ response -> getBody ( ) -> rewind ( ) ; return new static ( sprintf ( "Response body '%s' is missing the expected JSON path '%s'" , $ response -> getBody ( ) -> getContents ( ) , $ expectedPath ) ) ; }
|
Thrown when the response body is missing an expected JSON path .
|
57,344
|
public function getIndexEntries ( ContentItem $ entry ) { return $ this -> getEntityManager ( ) -> createQuery ( 'SELECT e FROM Skimpy\CMS\ContentItem e WHERE e.uri LIKE :uri AND e.isIndex = 0' ) -> setParameter ( 'uri' , $ entry -> getUri ( ) . '%' ) -> getResult ( ) ; }
|
Returns all entries in a subdirectory of Entry
|
57,345
|
public function assertIsStringAndNonEmpty ( $ value , $ message = '%s must be a string and not empty' , $ exception = 'Asserts' ) { if ( is_string ( $ value ) === false || strlen ( $ value ) < 1 ) { $ this -> throwException ( $ exception , $ message , $ value ) ; } }
|
Verifies that the specified condition is string and non empty . The assertion fails if the condition is not string or empty string .
|
57,346
|
public static function initializeConfigs ( string $ configPath = '.env' , bool $ absolutePath = true , string $ separator = '=' ) : void { self :: $ path = ( $ absolutePath ? $ _SERVER [ 'DOCUMENT_ROOT' ] : '' ) . $ configPath ; self :: $ separator = $ separator ; if ( ! file_exists ( self :: $ path ) ) { return ; } $ lines = file ( self :: $ path ) ; foreach ( $ lines as $ line ) { if ( trim ( rtrim ( $ line , "\n" ) ) == '' || trim ( $ line ) [ 0 ] == '#' ) { continue ; } $ parsedConfig = self :: parseContent ( $ line ) ; self :: $ configs [ $ parsedConfig [ 'key' ] ] = $ parsedConfig [ 'value' ] ; } self :: $ initialized = true ; }
|
Parse File to Config Array
|
57,347
|
public static function read ( string $ key ) { if ( ! self :: $ initialized ) { self :: initialize ( ) ; } return self :: $ configs [ $ key ] ; }
|
Read Config Value with Key
|
57,348
|
private static function parseContent ( string $ line ) : array { $ separatePosition = strpos ( $ line , self :: $ separator ) ; $ configName = trim ( substr ( $ line , 0 , $ separatePosition ) ) ; $ configValue = trim ( rtrim ( substr ( $ line , $ separatePosition + strlen ( self :: $ separator ) ) , "\n" ) ) ; if ( is_numeric ( $ configValue ) ) { if ( ( int ) $ configValue == $ configValue ) { $ configValue = ( int ) $ configValue ; } else { $ configValue = ( float ) $ configValue ; } } return [ 'key' => $ configName , 'value' => $ configValue ] ; }
|
Parse a Line to Key and Value
|
57,349
|
private static function convertConfigsToFile ( ) : string { $ content = '' ; $ separator = self :: $ separator ; foreach ( self :: $ configs as $ configName => $ configValue ) { $ content .= $ configName . $ separator . $ configValue . "\n" ; } return $ content ; }
|
Convert current configs to one string
|
57,350
|
public function getRequestCurrent ( $ optional = false ) { $ requestStack = $ this -> getRequestStack ( $ optional ) ; if ( null === $ requestStack ) { return null ; } return $ this -> getRequestStack ( $ optional ) -> getCurrentRequest ( ) ; }
|
Get current Request
|
57,351
|
public function processUrl ( $ url ) { $ splittedUrl = explode ( '/' , $ url ) ; $ langCodes = $ this -> getCodes ( ) ; if ( isset ( $ langCodes [ $ splittedUrl [ 0 ] ] ) ) { if ( $ this -> _accepted_languages !== null && is_array ( $ this -> _accepted_languages ) ) { if ( in_array ( $ splittedUrl [ 0 ] , $ this -> _accepted_languages ) ) { $ this -> _selectedLanguage = array_shift ( $ splittedUrl ) ; } else { $ this -> _selectedLanguage = $ this -> _defaultLang ; } } else { $ this -> _selectedLanguage = array_shift ( $ splittedUrl ) ; } $ this -> saveLanguage ( ) ; $ processedUrl = implode ( '/' , $ splittedUrl ) ; } elseif ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) && isset ( $ langCodes [ substr ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] , 0 , 2 ) ] ) ) { $ this -> _selectedLanguage = substr ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] , 0 , 2 ) ; if ( $ this -> _accepted_languages === null ) { $ this -> _selectedLanguage = $ this -> _defaultLang ; } elseif ( is_array ( $ this -> _accepted_languages ) ) { if ( ! in_array ( $ this -> _selectedLanguage , $ this -> _accepted_languages ) ) { $ this -> _selectedLanguage = $ this -> _defaultLang ; } } $ this -> saveLanguage ( ) ; $ processedUrl = $ url ; } else { $ this -> _selectedLanguage = $ this -> _defaultLang ; $ this -> saveLanguage ( ) ; $ processedUrl = $ url ; } return $ processedUrl ; }
|
Processes the url to find a language
|
57,352
|
private function saveLanguage ( ) { if ( $ this -> _saveOnCookies ) { $ this -> getRequiredModules ( 'cookies' ) -> setCookie ( $ this -> _cookieName , $ this -> _selectedLanguage , 30 * 24 ) ; } if ( $ this -> _saveOnSession ) { $ _SESSION [ $ this -> _sessionKeyName ] = $ this -> _selectedLanguage ; $ _SESSION [ 'default_language' ] = $ this -> _defaultLang ; } }
|
Saves the choosen language preference
|
57,353
|
public function chooseLanguage ( ) { if ( $ this -> _saveOnCookies && $ tmpLng = $ this -> getRequiredModules ( 'cookies' ) -> getCookie ( $ this -> _cookieName ) ) { $ this -> _selectedLanguage = $ tmpLng ; } elseif ( isset ( $ this -> _app ) ) { try { $ this -> _selectedLanguage = $ this -> _app -> getConfig ( ) -> getConfigData ( 'default_language' ) ; } catch ( \ pff \ ConfigException $ e ) { $ this -> _selectedLanguage = $ this -> _defaultLang ; } } else { $ this -> _selectedLanguage = $ this -> _defaultLang ; } }
|
Chooses a default language . First check for cookies then user configuration then module configuration
|
57,354
|
public function validate ( $ xmlString , $ schemaFile = null ) { $ doc = $ this -> _loadXmlDoc ( $ xmlString ) ; $ originalUseErrors = $ this -> _setupValidationErrorHandling ( ) ; $ isValid = $ doc -> schemaValidate ( $ schemaFile ) ; $ errors = $ this -> _retrieveErrors ( ) ; $ this -> _teardownValidationErrorHandling ( $ originalUseErrors ) ; if ( ! $ isValid ) { throw Mage :: exception ( 'Radial_RiskService_Sdk_Exception_Invalid_Payload' , $ this -> _formatErrors ( $ errors ) ) ; } return $ this ; }
|
Validate the serialized string as XML against a provided XSD schema .
|
57,355
|
protected function _formatErrors ( array $ libxmlErrors = array ( ) ) { return 'XSD validation failed with following messages:' . PHP_EOL . implode ( '' , array_map ( function ( \ libXMLError $ xmlError ) { return sprintf ( '[%s:%d] %s' , $ xmlError -> file , $ xmlError -> line , $ xmlError -> message ) ; } , $ libxmlErrors ) ) ; }
|
Format the array of validation errors .
|
57,356
|
public function useTwigTemplate ( $ template , array $ data = array ( ) ) { $ html = $ this -> renderer -> render ( $ template , $ data ) ; $ this -> setHtml ( $ html ) ; return $ this ; }
|
Renders and set as html the template with the given context
|
57,357
|
public function generate ( ) { if ( ! $ this -> mpdf ) { $ this -> init ( ) ; } $ output = $ this -> mpdf -> Output ( '' , 'S' ) ; $ time = microtime ( true ) - $ this -> start_time ; $ this -> logger -> debug ( "sasedev_mpdf: pdf generation took " . $ time . " seconds" ) ; return $ output ; }
|
Generate pdf document and return it as string
|
57,358
|
protected static function _renderImage ( $ src , $ className , array $ attributes = array ( ) ) { if ( is_array ( $ attributes [ 'class' ] ) ) { $ attributes [ 'class' ] [ ] = $ className ; } else { $ attributes [ 'class' ] .= ' ' . $ className ; } return sprintf ( '<img src="%s"%s />' , Html :: escape ( $ src ) , Html :: attributes ( $ attributes ) ) ; }
|
Renders the image tag
|
57,359
|
public function getSubscribedEvents ( ) { $ secret = $ this -> getSecret ( ) ; if ( true === empty ( $ secret ) ) { return [ ] ; } return [ Events :: postLoad , Events :: onFlush , ] ; }
|
Get Subscribed Events
|
57,360
|
public function registerRoute ( ) { if ( ! is_null ( $ services = $ this -> services ) ) { foreach ( $ services as $ service ) { $ routes = $ this -> app -> make ( $ service ) -> registerRoute ( ) ; $ this -> requiredRoute ( $ routes ) ; } } }
|
Register service provider routes
|
57,361
|
public function get ( $ key , $ default = null , $ separator = '.' ) { $ key = array_filter ( explode ( $ separator , $ key ) ) ; $ tmp = $ this -> data ; foreach ( $ key as $ k ) { if ( ! isset ( $ tmp [ $ k ] ) ) { return $ default ; } $ tmp = $ tmp [ $ k ] ; } return $ tmp ; }
|
Get a key from the storage by using a string locator .
|
57,362
|
public function set ( $ key , $ value , $ separator = '.' ) { $ key = array_filter ( explode ( $ separator , $ key ) ) ; $ tmp = & $ this -> data ; foreach ( $ key as $ k ) { if ( ! isset ( $ tmp [ $ k ] ) ) { $ tmp [ $ k ] = [ ] ; } $ tmp = & $ tmp [ $ k ] ; } return $ tmp = is_array ( $ tmp ) && is_array ( $ value ) && count ( $ tmp ) ? array_merge ( $ tmp , $ value ) : $ value ; }
|
Set an element in the storage to a specified value .
|
57,363
|
public function del ( $ key , $ separator = '.' ) { $ key = explode ( $ separator , $ key ) ; $ lst = array_pop ( $ key ) ; $ tmp = & $ this -> data ; foreach ( $ key as $ k ) { if ( ! isset ( $ tmp [ $ k ] ) ) { return null ; } $ tmp = & $ tmp [ $ k ] ; } if ( ! isset ( $ tmp [ $ lst ] ) ) { return null ; } $ val = $ tmp [ $ lst ] ; unset ( $ tmp [ $ lst ] ) ; return $ val ; }
|
Delete an element from the storage .
|
57,364
|
public static function hashEquals ( $ safe , $ user ) { if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( $ safe , $ user ) ; } return self :: timingSafeEquals ( $ safe , $ user ) ; }
|
Wrapper to compare two hashes in a timing safe way .
|
57,365
|
public function resizeTo ( int $ width , int $ height , bool $ maintain_aspect = true , array $ canvas_color = array ( 'r' => 255 , 'g' => 255 , 'b' => 255 ) ) : ImageResize { if ( $ this -> resizer !== null ) { try { $ this -> resizer -> setOptions ( $ width , $ height , $ this -> quality , $ maintain_aspect , $ canvas_color ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } } return $ this ; }
|
Set the resize to options
|
57,366
|
public function source ( string $ file , string $ path = '' ) : ImageResize { if ( $ this -> resizer !== null ) { try { $ this -> resizer -> loadImage ( $ file , $ path ) ; $ this -> loaded = true ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } } return $ this ; }
|
Set the source image
|
57,367
|
public function target ( string $ file , string $ path = '' ) : array { if ( $ this -> resizer !== null && $ this -> loaded === true ) { try { $ this -> resizer -> resizeSource ( ) -> createCopy ( ) -> setFileName ( $ file ) -> setPath ( $ path ) -> save ( ) ; return $ this -> resizer -> getInfo ( ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } } }
|
Set the file name and path for the target this will be your newly resized image
|
57,368
|
public function calculateViewValue ( $ id , $ view , & $ properties_cache = null , & $ view_cache = null , & $ persistent_view_cache = null ) { switch ( $ view ) { case 'user_login' : if ( $ this -> getState ( $ id ) ) { $ user = $ this -> getView ( $ id , 'user' , $ properties_cache , $ view_cache , $ persistent_view_cache ) ; return $ user && $ user -> state ? $ user [ $ this -> user_login_property ] : null ; } else { return null ; } case 'user_password' : if ( $ this -> getState ( $ id ) ) { $ user = $ this -> getView ( $ id , 'user' , $ properties_cache , $ view_cache , $ persistent_view_cache ) ; return $ user && $ user -> state ? $ user [ $ this -> user_password_property ] : null ; } else { return null ; } default : return parent :: calculateViewValue ( $ id , $ view , $ properties_cache , $ view_cache , $ persistent_view_cache ) ; } }
|
Resolve specific views
|
57,369
|
public static function createBlueDark ( ) { $ config = new DataSetConfig ( ) ; $ config -> setLineTension ( 0 ) -> setBorderWidth ( 2 ) -> setPointRadius ( 1 ) -> setPointHitRadius ( 5 ) -> setPointBorderColor ( 'rgb(94, 115, 139)' ) -> setBorderColor ( 'rgb(94, 115, 139)' ) -> setBackgroundColor ( 'rgba(94, 115, 139, 0.1)' ) ; return $ config ; }
|
Get Config Blue Dark
|
57,370
|
static function register ( iWrapperStream $ wrapper , $ label = null ) { if ( $ label == null ) $ label = $ wrapper -> getLabel ( ) ; if ( $ pos = strpos ( $ label , ':' ) !== false ) throw new \ Exception ( sprintf ( '(%s) Is Invalid Label Provided For Stream Wrapper.' . ' It must include just a name like "http".' , $ label ) ) ; stream_wrapper_register ( $ label , get_class ( $ wrapper ) ) ; $ options = array ( $ label => \ Poirot \ Std \ cast ( $ wrapper -> optsData ( ) ) -> toArray ( ) ) ; stream_context_set_default ( $ options ) ; }
|
Register Stream Wrapper
|
57,371
|
static function isRegistered ( $ wrapper ) { if ( $ wrapper instanceof iWrapperStream ) $ wrapper = $ wrapper -> getLabel ( ) ; return in_array ( $ wrapper , self :: listWrappers ( ) ) ; }
|
Has Registered Wrapper With Name?
|
57,372
|
public static function build ( $ data = [ ] ) { $ text = '<?xml version="1.0" encoding="UTF-8" ?>' . PHP_EOL ; foreach ( $ data as $ tg => $ ct ) { if ( is_array ( $ ct ) && isset ( $ ct [ 'content' ] ) && isset ( $ ct [ 'attribute' ] ) ) $ text .= self :: generateTag ( $ tg , $ ct [ 'content' ] , $ ct [ 'attribute' ] ) ; else $ text .= self :: generateTag ( $ tg , $ ct ) ; } return $ text ; }
|
Building the XML Only
|
57,373
|
public static function buildRSS ( $ data = [ ] ) { $ text = '<?xml version="1.0" encoding="UTF-8" ?>' . PHP_EOL ; $ text .= '<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">' . PHP_EOL ; $ text .= self :: generateTag ( 'channel' , $ data ) ; $ text .= '</rss>' . PHP_EOL ; return $ text ; }
|
Building the rss tag
|
57,374
|
protected static function generateTag ( $ tag , $ content , $ attributes = [ ] ) { $ text = '' ; $ attribute = self :: attribute ( $ attributes ) ; if ( is_string ( $ tag ) ) $ text .= "<{$tag}{$attribute}>" . PHP_EOL ; if ( is_array ( $ content ) ) { if ( isset ( $ content [ 'type' ] ) and $ content [ 'type' ] = 'cdata' ) { $ text .= "<![CDATA[" . PHP_EOL ; $ text .= $ content [ 'data' ] . PHP_EOL ; $ text .= "]]>" . PHP_EOL ; } else { foreach ( $ content as $ tg => $ ct ) { if ( is_array ( $ ct ) && isset ( $ ct [ 'content' ] ) && isset ( $ ct [ 'attribute' ] ) ) $ text .= self :: generateTag ( $ tg , $ ct [ 'content' ] , $ ct [ 'attribute' ] ) ; else $ text .= self :: generateTag ( $ tg , $ ct ) ; } } } elseif ( is_string ( $ content ) ) { $ text .= $ content ; } if ( is_string ( $ tag ) ) $ text .= "</{$tag}>" . PHP_EOL ; return $ text ; }
|
XML Tag Generator
|
57,375
|
protected static function attribute ( $ attributes = [ ] ) { $ text = '' ; foreach ( $ attributes as $ option => $ value ) { $ text = ' ' . $ option . '="' . $ value . '"' ; } return $ text ; }
|
Generate Attribute tag
|
57,376
|
public function load ( array $ routesConfig ) { foreach ( $ routesConfig as $ route ) { $ pattern = $ route [ 0 ] ; $ handler = $ route [ 1 ] ?? null ; $ methods = $ route [ 2 ] ?? '*' ; $ this -> map ( $ pattern , $ handler , $ methods ) ; } return $ this -> routes ; }
|
Load routes config .
|
57,377
|
public function listAction ( Request $ request ) { return $ this -> render ( 'SynapsePageBundle:Admin/Page:list.html.twig' , array ( 'pages' => $ this -> container -> get ( 'synapse.page.loader' ) -> retrieveAll ( ) , 'page_rendering_route' => $ this -> container -> getParameter ( 'synapse.page.rendering_route' ) , ) ) ; }
|
Page list action .
|
57,378
|
public static function createProtocolMessage ( Message $ msg ) { $ version = $ msg -> shift ( ) ; if ( ! self :: hasProtocolVersion ( ( $ version ) ) ) { throw new UnknownProtocolVersionException ( ) ; } $ type = $ msg -> shift ( ) ; $ class = self :: getClassByType ( $ type ) ; return $ class :: fromMessage ( $ msg ) ; }
|
Create a Message with the given Type .
|
57,379
|
private static function getClassByType ( $ type ) { if ( ! isset ( self :: $ types [ $ type ] ) ) { throw new UnknownMessageException ( 'Unable to parse message because type (' . $ type . ')' . ' is not mapped.' ) ; } return self :: $ types [ $ type ] ; }
|
Returns the Message class for the given Message type number .
|
57,380
|
public static function getTypeIdByClass ( $ className ) { if ( null === self :: $ typesByClass ) { self :: $ typesByClass = array_flip ( self :: $ types ) ; } if ( ! isset ( self :: $ typesByClass [ $ className ] ) ) { throw new UnknownMessageException ( 'Class not registered: ' . $ className . '.' ) ; } return self :: $ typesByClass [ $ className ] ; }
|
Get the Type ID for the given class .
|
57,381
|
public function actionStop ( $ trys = 3 ) { $ pid = $ this -> getMasterPid ( ) ; Console :: stdout ( "stopping $pid ..." ) ; while ( $ trys > 0 ) { if ( ! posix_kill ( $ pid , SIGTERM ) ) { Console :: stdout ( " success.\r\n" ) ; exit ( 0 ) ; } $ trys -- ; usleep ( 300000 ) ; } if ( $ trys <= 0 ) { Console :: error ( " failed !\r\n" ) ; } exit ( 5 ) ; }
|
stop the server .
|
57,382
|
public function actionReload ( ) { $ pid = $ this -> getMasterPid ( ) ; if ( ! extension_loaded ( 'posix' ) ) { Console :: error ( "posix extension is not loaded" ) ; exit ( 6 ) ; } Console :: stdout ( "reloading beyod($pid) ..." ) ; Yii :: debug ( "send SIGUSR1 to $pid " , 'beyod' ) ; $ res = posix_kill ( $ pid , SIGUSR1 ) ; Console :: stdout ( ( $ res ? " success " : " failed" ) . "\r\n" ) ; }
|
reload the server s worker process graced .
|
57,383
|
public function actionStatus ( ) { $ pid = $ this -> getMasterPid ( ) ; Console :: stdout ( "beyod($pid) is running ...\r\n" ) ; Console :: stdout ( "php ini: " . php_ini_loaded_file ( ) . "\r\n" ) ; Console :: stdout ( "php version: " . phpversion ( ) . "\r\n" ) ; Console :: stdout ( "necessary extensions status:\r\n" ) ; foreach ( [ 'pcntl' , 'event' , 'posix' ] as $ ext ) { Console :: stdout ( "\t$ext: \t" . ( extension_loaded ( $ ext ) ? 'yes' : 'no' ) . "\r\n" ) ; } }
|
output the server s status
|
57,384
|
private function prepareRoleCollection ( array $ roleConfiguration ) { $ preparedRoles = [ ] ; foreach ( $ roleConfiguration as $ roleKey => $ configuration ) { $ preparedRoles [ $ roleKey ] = Role :: createFromConfiguration ( $ roleKey , $ configuration ) ; } foreach ( $ roleConfiguration as $ roleKey => $ configuration ) { if ( ! isset ( $ configuration [ "actions" ] ) || ! is_array ( $ configuration [ "actions" ] ) ) { continue ; } foreach ( $ configuration [ "actions" ] as $ action ) { if ( ! isset ( $ preparedRoles [ $ action ] ) ) { $ preparedRoles [ $ action ] = new BaseRole ( $ action ) ; } } $ includedActions = array_map ( function ( $ role ) use ( $ preparedRoles ) { return $ preparedRoles [ $ role ] ; } , $ configuration [ "actions" ] ) ; $ preparedRoles [ $ roleKey ] -> setIncludedActions ( $ includedActions ) ; } foreach ( $ roleConfiguration as $ roleKey => $ configuration ) { if ( ! isset ( $ configuration [ "included_roles" ] ) || ! is_array ( $ configuration [ "included_roles" ] ) ) { continue ; } $ includedRoles = array_map ( function ( $ role ) use ( $ preparedRoles ) { return $ preparedRoles [ $ role ] ; } , $ configuration [ "included_roles" ] ) ; $ preparedRoles [ $ roleKey ] -> setIncludedRoles ( $ includedRoles ) ; } return $ preparedRoles ; }
|
Prepares the role collection by transforming the config array to an object structure
|
57,385
|
public function getAllIncludedRoles ( array $ roles ) { $ allIncludedRoles = [ ] ; foreach ( $ this -> normalizeRoleList ( $ roles ) as $ role ) { $ includedRoleCollection = [ ] ; $ this -> findIncludedRoles ( $ role , $ includedRoleCollection ) ; $ allIncludedRoles = array_replace ( $ allIncludedRoles , $ includedRoleCollection ) ; $ includedActionCollection = [ ] ; $ this -> findIncludedActions ( $ role , $ includedActionCollection ) ; $ allIncludedRoles = array_replace ( $ allIncludedRoles , $ includedActionCollection ) ; } return $ allIncludedRoles ; }
|
Finds all included roles of a set of base roles
|
57,386
|
private function normalizeRoleList ( array $ roles ) { $ normalized = [ ] ; foreach ( $ roles as $ role ) { $ roleKey = ( is_object ( $ role ) && ( $ role instanceof BaseRole ) ) ? $ role -> getRole ( ) : ( string ) $ role ; if ( isset ( $ this -> roleCollection [ $ roleKey ] ) ) { $ normalized [ ] = $ this -> roleCollection [ $ roleKey ] ; } } return $ normalized ; }
|
Normalizes the role list
|
57,387
|
public function getAllAvailableRoles ( ) { return array_filter ( $ this -> roleCollection , function ( BaseRole $ role ) { if ( $ role instanceof Role ) { return ! $ role -> isHidden ( ) ; } return false ; } ) ; }
|
Returns a list of all roles
|
57,388
|
public function getRoleByKey ( $ roleKey ) { return array_key_exists ( $ roleKey , $ this -> roleCollection ) ? $ this -> roleCollection [ $ roleKey ] : null ; }
|
Returns a Role by key
|
57,389
|
public function parse ( ) { $ annotations = [ ] ; preg_match_all ( self :: ANNOTATION_PATTERN , $ this -> rawDocComment , $ found ) ; foreach ( $ found [ 1 ] as $ key => $ value ) { $ arg = null ; if ( ! empty ( $ found [ 2 ] [ $ key ] ) ) { $ arg = substr ( trim ( $ found [ 2 ] [ $ key ] ) , 1 , - 1 ) ; } $ annotations [ ] = new Annotation ( $ value , $ this -> parseValue ( $ found [ 3 ] [ $ key ] ) , $ arg ) ; } return $ annotations ; }
|
Obtains the list of annotations in a doc comment
|
57,390
|
public static function reset ( ) { self :: $ loader = null ; self :: $ builder = null ; self :: $ fixtures = null ; self :: $ triggers = null ; self :: $ hasOneRelationshipClass = '\Phactory\HasOneRelationship' ; self :: $ dependencyClass = '\Phactory\Dependency' ; }
|
Reset all Phactory settings to default
|
57,391
|
public static function hasOne ( $ name , $ arguments = array ( ) ) { $ arguments = func_get_args ( ) ; array_shift ( $ arguments ) ; list ( $ type , $ override ) = self :: resolveArgs ( $ arguments ) ; return new self :: $ hasOneRelationshipClass ( $ name , $ type , $ override ) ; }
|
Define an attribute that requires another factory generated object
|
57,392
|
public static function createBlueprint ( $ name , $ type , $ override = array ( ) , $ persisted = true ) { if ( self :: fixtures ( ) -> hasFixture ( $ name , $ type ) ) { return self :: fixtures ( ) -> getFixture ( $ name , $ type ) ; } $ blueprint = self :: getBlueprint ( $ name , $ type , $ override , $ persisted ) ; $ object = self :: builder ( ) -> create ( $ blueprint ) ; if ( $ blueprint -> isFixture ( ) ) { self :: fixtures ( ) -> setFixture ( $ name , $ type , $ object ) ; } return $ object ; }
|
Loads prepare persist and return a factory generated object
|
57,393
|
public static function getBlueprint ( $ name , $ type , $ override = array ( ) , $ persisted = true ) { $ factory = self :: loader ( ) -> load ( $ name ) ; return $ factory -> create ( $ type , $ override , $ persisted ) ; }
|
Returns an object blueprint
|
57,394
|
public static function loader ( $ loader = null ) { if ( is_object ( $ loader ) ) { self :: $ loader = $ loader ; } return isset ( self :: $ loader ) ? self :: $ loader : self :: $ loader = new Loader ; }
|
Get factory loader . If it is not defined it will be set .
|
57,395
|
public static function builder ( $ builder = null ) { if ( is_object ( $ builder ) ) { self :: $ builder = $ builder ; } return isset ( self :: $ builder ) ? self :: $ builder : self :: $ builder = new Builder ; }
|
Get object builder . If it is not defined it will be set .
|
57,396
|
public static function triggers ( $ triggers = null ) { if ( is_object ( $ triggers ) ) { self :: $ triggers = new Triggers ( $ triggers ) ; } return isset ( self :: $ triggers ) ? self :: $ triggers : self :: $ triggers = new Triggers ; }
|
Get triggers events caller . If it is not defined it will be set .
|
57,397
|
public static function toFile ( Stringset $ set , $ file ) { if ( ! file_exists ( $ file ) || is_writable ( $ file ) ) { file_put_contents ( $ file , self :: toString ( $ set ) ) ; } else { throw new Exception ( "Could not write output to file." ) ; } }
|
Write the given Stringset to a mo file .
|
57,398
|
private static function makeHashTable ( Stringset $ set , $ size ) { $ table = array ( ) ; for ( $ i = 0 ; $ i < $ size ; $ i += 1 ) { $ table [ $ i ] = 0 ; } for ( $ i = 0 ; $ i < $ set -> size ( ) ; $ i += 1 ) { $ item = $ set -> item ( $ i ) ; $ hash = self :: hash ( $ item [ 'id' ] ) ; $ index = $ hash % $ size ; $ inc = ( $ hash % ( $ size - 2 ) ) + 1 ; while ( $ table [ $ index ] !== 0 ) { if ( $ index < $ size - $ inc ) { $ index += $ inc ; } else { $ index -= $ size - $ inc ; } } $ table [ $ index ] = $ i + 1 ; } return $ table ; }
|
Generate the hashtable . Uses an array which is ... a hashtable . Clearly this is a case of hashtableception .
|
57,399
|
private static function hash ( $ str ) { $ hash = 0 ; $ str = str_split ( $ str , 1 ) ; foreach ( $ str as $ char ) { $ hash = ( $ hash << 4 ) + ord ( $ char ) ; $ g = $ hash & ( 0xf << ( self :: INT_SIZE - 4 ) ) ; if ( $ g !== 0 ) { $ hash = $ hash ^ ( $ g >> self :: INT_SIZE - 8 ) ; $ hash = $ hash ^ $ g ; } } return $ hash ; }
|
Generates a hash from a given string .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.