idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
200 | public function getModulesConfig ( ) { $ result = [ ] ; foreach ( $ this -> modules as $ moduleName => $ moduleConfig ) { $ className = $ moduleConfig [ 'className' ] ; $ module = new $ className ; if ( ! $ module instanceof AbstractModule ) { $ errMsg = sprintf ( 'Class "%s" must be extended from %s' , $ className , AbstractModule :: class ) ; throw new Exception \ RuntimeException ( $ errMsg ) ; } $ config = $ module -> getConfig ( ) ; $ result = ArrayUtils :: merge ( $ result , $ this -> filterModuleConfig ( $ config , $ moduleName ) ) ; } return $ result ; } | Get config in modules |
201 | public function getModulesAutoloadConfig ( ) { $ isCacheInstance = $ this -> cache instanceof CacheInterface ; if ( $ isCacheInstance ) { if ( ( $ autoloadConfig = $ this -> cache -> getAutoloadModulesConfig ( ) ) !== false ) { return $ autoloadConfig ; } } $ autoloadConfig = $ this -> getModulesAutoloadConfigWithoutCache ( ) ; if ( $ isCacheInstance ) { $ this -> cache -> setAutoloadModulesConfig ( $ autoloadConfig ) ; } return $ autoloadConfig ; } | Get all module auto loader configuration |
202 | public function onResponse ( FilterResponseEvent $ event ) { $ kernel = $ event -> getKernel ( ) ; $ response = $ event -> getResponse ( ) ; $ content = $ response -> getContent ( ) ; foreach ( $ this -> toolbar -> getExtensions ( ) as $ extension ) { $ extension -> buildData ( ) ; } if ( false !== strpos ( $ content , '</body>' ) ) { $ debug = $ this -> engine -> render ( 'TridentDebugModule:Toolbar:toolbar.html.twig' , [ 'extensions' => $ this -> toolbar -> getExtensions ( ) ] ) ; $ content = str_replace ( '</body>' , $ debug . PHP_EOL . '</body>' , $ content ) ; $ response -> setContent ( $ content ) ; } } | Response event action . |
203 | public function getValue ( ) : ? Range { if ( ! empty ( $ this -> value ) ) { $ result = new Range ; @ list ( $ from , $ to ) = explode ( $ this -> delimiter , $ this -> value ) ; if ( $ from && $ to ) { $ result -> from = DateTime :: createFromFormat ( $ this -> format , $ from ) ; $ result -> to = DateTime :: createFromFormat ( $ this -> format , $ to ) ; return $ result ; } } return null ; } | Vrati pole intervalu datumu |
204 | protected function _parseArg ( $ argv ) { for ( $ i = 0 ; $ i < count ( $ argv ) ; $ i ++ ) { if ( $ argv [ $ i ] != 'console' ) { if ( ! preg_match ( '#\[#' , $ argv [ $ i ] ) ) { array_push ( $ this -> _argv , $ argv [ $ i ] ) ; } else { $ data = '' ; for ( $ i = 0 ; $ i < count ( $ argv ) ; $ i ++ ) { $ data .= $ argv [ $ i ] . ' ' ; if ( preg_match ( '#\]#' , $ argv [ $ i ] ) ) { $ data = str_replace ( [ '[' , ']' ] , [ '' , '' ] , $ data ) ; array_push ( $ this -> _argv , trim ( $ data ) ) ; break ; } } } } } } | Parse terminal parameters to allow user to use spaces |
205 | public static function rrmdir ( $ dir , $ removeDir = false , $ except = [ ] ) { if ( is_dir ( $ dir ) ) { $ objects = scandir ( $ dir ) ; foreach ( $ objects as $ object ) { if ( $ object != "." && $ object != ".." ) { if ( filetype ( $ dir . "/" . $ object ) == "dir" ) { Terminal :: rrmdir ( $ dir . "/" . $ object , $ removeDir , $ except ) ; if ( $ removeDir == true ) { rmdir ( $ dir . "/" . $ object . '/' ) ; } } else { if ( ! in_array ( $ object , $ except ) ) { unlink ( $ dir . "/" . $ object ) ; } } } } reset ( $ objects ) ; } } | Remove directory content |
206 | public function indexAction ( Request $ request ) { $ viewIndex = $ this -> get ( 'phlexible_gui.view.index' ) ; return [ 'scripts' => $ viewIndex -> get ( $ request ) , 'noScript' => $ viewIndex -> getNoScript ( ) , ] ; } | Render Frame . |
207 | public function menuAction ( ) { $ loader = $ this -> get ( 'phlexible_gui.menu.loader' ) ; $ items = $ loader -> load ( ) ; $ data = $ items -> toArray ( ) ; return new JsonResponse ( $ data ) ; } | Return menu . |
208 | public function routesAction ( Request $ request ) { $ routeExtractor = $ this -> get ( 'phlexible_gui.route_extractor' ) ; $ extractedRoutes = $ routeExtractor -> extract ( $ request ) ; $ content = sprintf ( 'Phlexible.Router.setData(%s);' , json_encode ( array ( 'baseUrl' => $ extractedRoutes -> getBaseUrl ( ) , 'basePath' => $ extractedRoutes -> getBasePath ( ) , 'routes' => $ extractedRoutes -> getRoutes ( ) , ) ) ) ; return new Response ( $ content , 200 , [ 'Content-type' => 'text/javascript; charset=utf-8' ] ) ; } | Return routes . |
209 | public static function buildAttribString ( $ attribs , $ dblEnc = false ) { if ( ! $ dblEnc && \ is_array ( $ attribs ) ) { foreach ( $ attribs as $ k => $ v ) { if ( \ is_string ( $ v ) ) { $ attribs [ $ k ] = \ htmlspecialchars_decode ( $ v ) ; } } } return \ bdk \ Debug \ Utilities :: buildAttribString ( $ attribs ) ; } | Build an attribute string |
210 | public static function buildTag ( $ name , $ attribs = array ( ) , $ innerhtml = '' , $ dblEnc = false ) { $ attribStr = self :: buildAttribString ( $ attribs , $ dblEnc ) ; return \ in_array ( $ name , self :: $ cfgStatic [ 'emptyTags' ] ) ? '<' . $ name . $ attribStr . ' />' : '<' . $ name . $ attribStr . '>' . $ innerhtml . '</' . $ name . '>' ; } | Build an html tag |
211 | public static function getAbsUrl ( $ urlFrom , $ urlTo ) { if ( strpos ( $ urlTo , '://' ) !== false ) { return $ urlTo ; } $ urlAbs = $ urlTo ; if ( is_array ( $ urlFrom ) ) { $ urlParts = $ urlFrom ; } else { $ urlParts = Html :: parseUrl ( $ urlFrom ) ; } $ urlParts [ 'query' ] = null ; $ urlParts [ 'params' ] = array ( ) ; $ urlParts [ 'fragment' ] = null ; $ path = '' ; if ( $ urlTo { 0 } != '/' ) { preg_match ( '/^(\/.*\/)/' , $ urlParts [ 'path' ] , $ matches ) ; $ path = isset ( $ matches [ 1 ] ) ? $ matches [ 1 ] : '/' ; } $ path .= $ urlTo ; $ pathSegs = explode ( '/' , $ path ) ; $ pathStack = array ( ) ; foreach ( $ pathSegs as $ k => $ seg ) { if ( $ seg === '' && $ k != 0 && $ k < count ( $ pathSegs ) - 1 ) { continue ; } elseif ( $ seg === '.' ) { continue ; } elseif ( $ seg === '..' ) { if ( array_pop ( $ pathStack ) === '' ) { $ pathStack [ ] = '' ; } } else { $ pathStack [ ] = $ seg ; } } $ urlParts [ 'path' ] = implode ( '/' , $ pathStack ) ; $ urlAbs = Html :: buildUrl ( $ urlParts ) ; return $ urlAbs ; } | Get absolute URL |
212 | public static function htmlentities ( $ str = '' , $ encodeTags = true , $ isXml = false , $ charset = null ) { $ debug = \ bdk \ Debug :: getInstance ( ) ; $ dbWas = $ debug -> setCfg ( 'collect' , false ) ; $ debug -> groupCollapsed ( __FUNCTION__ ) ; $ return = '' ; $ charsetsTry = array ( 'UTF-8' , 'ISO-8859-1' ) ; $ debug -> log ( 'charset' , $ charset ) ; if ( is_null ( $ charset ) && extension_loaded ( 'mbstring' ) ) { $ charset = mb_detect_encoding ( $ str , mb_detect_order ( ) , true ) ; $ debug -> log ( 'charset detected' , $ charset ) ; } if ( $ charset ) { $ charset = self :: getCharset ( $ charset ) ; if ( $ charset == 'UTF-8' && ! Str :: isUtf8 ( $ str ) ) { $ charset = null ; } } if ( $ charset ) { array_unshift ( $ charsetsTry , $ charset ) ; $ charsetsTry = array_unique ( $ charsetsTry ) ; } $ debug -> log ( 'charsetsTry' , implode ( ', ' , $ charsetsTry ) ) ; $ return = self :: htmlentitiesApply ( $ str , $ encodeTags , $ isXml , $ charsetsTry ) ; $ debug -> groupEnd ( ) ; $ debug -> setCfg ( 'collect' , $ dbWas ) ; return $ return ; } | Convert all applicable characters to HTML entities .. does not double encode |
213 | public static function parseAttribString ( $ str , $ decode = true , $ decodeData = true ) { return \ bdk \ Debug \ Utilities :: parseAttribString ( $ str , $ decode , $ decodeData ) ; } | Parse string - o - attributes into a key = > value array |
214 | private static function getSelfUrlParams ( $ requestParams , $ paramsNew , $ opts ) { $ params = $ requestParams ; $ paramsQuery = Str :: parse ( $ _SERVER [ 'QUERY_STRING' ] ) ; $ cor = array_diff_assoc ( $ paramsQuery , $ _GET ) ; $ coa = array_diff_assoc ( $ _GET , $ paramsQuery ) ; foreach ( $ cor as $ k => $ v ) { if ( ! isset ( $ coa [ $ k ] ) ) { unset ( $ params [ $ k ] ) ; } elseif ( isset ( $ coa [ $ k ] ) && $ coa [ $ k ] != $ v ) { continue ; } elseif ( ! isset ( $ requestParams [ $ k ] ) ) { unset ( $ coa [ $ k ] ) ; } } foreach ( $ coa as $ k => $ v ) { $ params [ $ k ] = $ v ; } if ( ! empty ( $ opts [ 'getLock' ] ) ) { foreach ( $ opts [ 'getLock' ] as $ k ) { if ( isset ( $ params [ $ k ] ) ) { $ params [ $ k ] = isset ( $ requestParams [ $ k ] ) ? $ requestParams [ $ k ] : null ; } } } if ( ! $ opts [ 'keepParams' ] ) { foreach ( $ params as $ k => $ v ) { if ( ! in_array ( $ k , $ opts [ 'getProp' ] ) ) { unset ( $ params [ $ k ] ) ; } } } foreach ( $ paramsNew as $ k => $ v ) { $ params [ $ k ] = $ v ; } return $ params ; } | get parameters for self url |
215 | protected function parse ( $ data ) { $ parsed = array ( ) ; $ parts = explode ( $ this -> normaliseWhitespace ( $ this -> fieldSeparator ) , $ this -> normaliseWhitespace ( trim ( $ data , " \t" ) ) ) ; if ( sizeof ( $ parts ) < 2 ) { throw new DomainException ( sprintf ( 'Expected a well-formed line of two fields "name%svalue", got: "%s".' , $ this -> fieldSeparator , $ this -> originalLine ) ) ; } $ parsed [ self :: FIELD_NAME ] = array_shift ( $ parts ) ; $ value = implode ( $ this -> fieldSeparator , $ parts ) ; if ( substr ( $ value , 0 , 1 ) === '"' && substr ( $ value , - 1 ) === '"' ) { $ value = substr ( $ value , 1 , - 1 ) ; } $ parsed [ self :: FIELD_VALUE ] = $ value ; return $ parsed ; } | Parsed a simple name separator value line into a name value pair . |
216 | public static function addBaseVariables ( array $ data = [ ] , ? string $ channel = null ) { $ channel = $ channel ?? static :: getDefaultChannel ( ) ; static :: $ baseData [ $ channel ] = static :: $ baseData [ $ channel ] ?? [ ] ; static :: $ baseData [ $ channel ] = array_merge ( static :: $ baseData [ $ channel ] , $ data ) ; } | Adds some data with specified channel to base data of all objects which will be created witch same channel afterwards |
217 | public function modifyValues ( $ modifiers , $ subKey = null ) { $ process = function ( & $ source ) use ( $ modifiers ) { foreach ( $ modifiers as $ key => $ value ) { if ( is_callable ( $ value ) ) { $ source [ $ key ] = $ value ( ( isset ( $ source [ $ key ] ) ? $ source [ $ key ] : null ) ) ; } else { $ source [ $ key ] = $ value ; } } } ; if ( is_array ( $ modifiers ) ) { if ( is_null ( $ subKey ) || ! isset ( $ this -> data [ $ subKey ] ) ) { $ process ( $ this -> data ) ; } else { $ wrongSubKey = new \ InvalidArgumentException ( sprintf ( "Wrong subKey given (%s), have no array value by this sub key" , $ subKey ) ) ; ; if ( ! is_array ( $ this -> data [ $ subKey ] ) ) { throw $ wrongSubKey ; } array_map ( function ( $ el ) use ( $ wrongSubKey ) { if ( ! is_array ( $ el ) ) throw $ wrongSubKey ; } , $ this -> data [ $ subKey ] ) ; foreach ( $ this -> data [ $ subKey ] as $ key => $ data ) { $ process ( $ this -> data [ $ subKey ] [ $ key ] ) ; } } } return $ this ; } | Modify stored value with callable or scalar modifiers |
218 | public function getProperties ( $ value , ReflectionClass $ class , $ propertyFilter ) { $ properties = [ ] ; foreach ( self :: $ appProperties as $ property ) { try { $ val = $ value -> $ property ( ) ; if ( ! is_null ( $ val ) ) $ properties [ $ property ] = $ val ; } catch ( Exception $ e ) { } } return $ properties ; } | Get an array of Application object properties . |
219 | public function filterFrontend ( CollectionInterface $ results ) { return $ results -> filter ( function ( Language $ language ) { return $ language -> available_at_frontend === true ; } ) ; } | Filter the provided result set by languages that are available at the frontend . |
220 | public function filterBackend ( CollectionInterface $ results ) { return $ results -> filter ( function ( Language $ language ) { return $ language -> available_at_backend === true ; } ) ; } | Filter the provided result set by languages that are available at the backend . |
221 | public function addFile ( $ file , $ options = [ ] ) { if ( empty ( $ file ) || ! is_string ( $ file ) ) { throw new InvalidParamException ( 'Filename must be a string and cannot be empty' ) ; } elseif ( ! is_array ( $ options ) ) { throw new InvalidParamException ( 'Options value must be an array' ) ; } $ this -> files [ $ file ] = $ options ; return $ this ; } | Adds JS file into a module |
222 | public function addDependency ( ModuleInterface $ depends ) { if ( $ depends -> getFiles ( ) === [ ] ) { foreach ( $ depends -> getDependencies ( ) as $ dependency ) { $ this -> addDependency ( $ dependency ) ; } return $ this ; } $ this -> dependencies [ $ depends -> getName ( ) ] = $ depends ; return $ this ; } | Adds dependency to a module |
223 | protected function _modify ( array $ data = null ) { if ( $ this -> is_valid ( ) ) { if ( isset ( $ data [ 'password' ] ) ) { $ this -> password = Auth :: hash ( $ data [ 'password' ] ) ; } return $ this -> save ( ) ; } return $ this -> errors -> full_messages ( ) ; } | Check validation and hashing password |
224 | public function configure ( ) { $ this -> setEnv ( $ this -> getEnvFromEnvironmentVariables ( ) ) ; $ this -> config ( 'directory.root' , dirname ( dirname ( __DIR__ ) ) ) ; $ this -> addAppPathUsePsr4 ( __DIR__ , __NAMESPACE__ , 'Samurai\\' , self :: PRIORITY_LOW ) ; $ this -> config ( 'directory.config.samurai' , 'Config/Samurai' ) ; $ this -> config ( 'directory.config.routing' , 'Config/App' ) ; $ this -> config ( 'directory.config.database' , 'Config/Database' ) ; $ this -> config ( 'directory.config.renderer' , 'Config/Renderer' ) ; $ this -> config ( 'directory.controller' , 'Controller' ) ; $ this -> config ( 'directory.model' , 'Model' ) ; $ this -> config ( 'directory.filter' , 'Filter' ) ; $ this -> config ( 'directory.layout' , 'View/Layout' ) ; $ this -> config ( 'directory.template' , 'View' ) ; $ this -> config ( 'directory.database.data' , 'Database' ) ; $ this -> config ( 'directory.database.migration' , 'Database/Migration' ) ; $ this -> config ( 'directory.database.seed' , 'Database/Seed' ) ; $ this -> config ( 'directory.database.schema' , 'Database/Schema' ) ; $ this -> config ( 'directory.locale' , 'Locale' ) ; $ this -> config ( 'directory.task' , 'Task' ) ; $ this -> config ( 'directory.spec' , 'Spec' ) ; $ this -> config ( 'directory.skeleton' , 'Skeleton' ) ; $ this -> config ( 'directory.log' , 'Log' ) ; $ this -> config ( 'directory.temp' , 'Temp' ) ; $ this -> config ( 'controller.namespaces' , [ 'Samurai\Samurai' ] ) ; $ this -> config ( 'container.dicon.' , 'Config/Samurai/samurai.dicon' ) ; $ this -> config ( 'encoding.input' , 'UTF-8' ) ; $ this -> config ( 'encoding.output' , 'UTF-8' ) ; $ this -> config ( 'encoding.internal' , 'UTF-8' ) ; $ this -> config ( 'encoding.text.html' , 'UTF-8' ) ; $ this -> config ( 'cache.yaml.enable' , true ) ; $ this -> config ( 'cache.yaml.expire' , 60 * 60 * 24 ) ; $ this -> config ( 'locale' , 'ja' ) ; $ this -> setTimezone ( 'Asia/Tokyo' ) ; $ loader = new Loader ( $ this ) ; $ loader -> register ( ) ; $ this -> loader = $ loader ; } | base configure . |
225 | protected function initializers ( ) { $ initializers = [ ] ; $ initializer_files = $ this -> loader -> find ( 'Config/Initializer/*Initializer.php' ) ; foreach ( $ initializer_files as $ file ) { require_once $ file -> getRealPath ( ) ; $ class = $ file -> getClassName ( ) ; $ initializers [ ] = new $ class ( ) ; } usort ( $ initializers , function ( $ a , $ b ) { return $ a -> getPriority ( ) - $ b -> getPriority ( ) ; } ) ; foreach ( $ initializers as $ initializer ) { $ initializer -> configure ( $ this ) ; } } | call initializers . |
226 | public function environment ( ) { $ env = $ this -> getEnv ( ) ; $ name = 'Config/Environment/' . ucfirst ( $ env ) . '.php' ; foreach ( $ this -> loader -> find ( $ name ) as $ file ) { require_once $ file -> getRealPath ( ) ; $ class = $ file -> getClassName ( ) ; $ initializer = new $ class ( ) ; $ initializer -> configure ( $ this ) ; } } | environment settings . |
227 | public function setEnv ( $ env ) { if ( ! $ env ) $ env = self :: ENV_DEVELOPMENT ; $ this -> env = $ env ; $ this -> config ( 'env' , $ this -> env ) ; return $ this -> getEnv ( ) ; } | set env . |
228 | public function config ( $ key = null , $ value = null ) { if ( ! $ key ) return $ this -> config ; $ is_array = false ; if ( substr ( $ key , - 1 ) === '.' ) { $ is_array = true ; $ key = substr ( $ key , 0 , - 1 ) ; } if ( $ value !== null ) { if ( $ is_array ) { if ( ! array_key_exists ( $ key , $ this -> config ) ) $ this -> config [ $ key ] = array ( ) ; array_push ( $ this -> config [ $ key ] , $ value ) ; } else { $ this -> config [ $ key ] = $ value ; } } if ( substr ( $ key , - 1 ) === '*' ) { $ config = [ ] ; $ key_quoted = preg_quote ( substr ( $ key , 0 , - 1 ) , '/' ) ; foreach ( $ this -> config as $ _key => $ _val ) { if ( preg_match ( "/^{$key_quoted}.*/" , $ _key ) ) { $ config [ $ _key ] = $ _val ; } } return $ config ; } else { return array_key_exists ( $ key , $ this -> config ) ? $ this -> config [ $ key ] : null ; } } | accessor config . |
229 | public function configHierarchical ( $ key = null ) { $ config = [ ] ; $ all = $ this -> config ( $ key ) ; if ( ! is_array ( $ all ) ) $ all = array ( $ key => $ all ) ; foreach ( $ all as $ _key => $ _val ) { $ keys = explode ( '.' , $ _key ) ; $ value = & $ config ; while ( $ key = array_shift ( $ keys ) ) { if ( $ keys ) { if ( ! isset ( $ value [ $ key ] ) ) $ value [ $ key ] = [ ] ; $ value = & $ value [ $ key ] ; } else { $ value [ $ key ] = $ _val ; } } } return $ config ; } | get config hierarchical splited by dot . |
230 | public function addAppPathUsePsr4 ( $ path , $ namespace , $ psr4_prefix , $ priority = self :: PRIORITY_LOW ) { $ dirs = $ this -> config ( 'directory.apps' ) ; if ( ! $ dirs ) $ dirs = [ ] ; $ root = substr ( $ path , 0 , - 1 - strlen ( $ namespace ) + strlen ( $ psr4_prefix ) ) ; $ dirs [ ] = [ 'dir' => $ path , 'root' => $ root , 'namespace' => $ namespace , 'priority' => $ priority , 'index' => count ( $ dirs ) ] ; usort ( $ dirs , function ( $ a , $ b ) { if ( $ a [ 'priority' ] == $ b [ 'priority' ] ) { return $ a [ 'index' ] > $ b [ 'index' ] ? - 1 : 1 ; } return $ a [ 'priority' ] > $ b [ 'priority' ] ? - 1 : 1 ; } ) ; $ this -> config ( 'directory.apps' , $ dirs ) ; $ this -> config ( 'directory.app' , $ dirs [ 0 ] [ 'dir' ] ) ; Namespacer :: register ( $ namespace , $ path ) ; } | add application path using psr4 . |
231 | public function getControllerDirectories ( ) { $ dirs = [ ] ; $ controller_ns = $ this -> config ( 'controller.namespaces' ) ; foreach ( $ this -> config ( 'directory.apps' ) as $ dir ) { if ( in_array ( $ dir [ 'namespace' ] , $ controller_ns ) ) $ dirs [ ] = $ dir [ 'dir' ] . DS . 'Controller' ; } return $ dirs ; } | get controller dirs |
232 | public function getValue ( ) { if ( ! isset ( $ this -> input [ $ this -> inputName ] ) ) { return null ; } return $ this -> input [ $ this -> inputName ] ; } | Return the value to be validated |
233 | public function getArg ( $ pos = null ) { if ( $ pos === null ) { return $ this -> args ; } return isset ( $ this -> args [ $ pos ] ) ? $ this -> args [ $ pos ] : $ this -> args ; } | Get arg or args |
234 | public function getRoutesWithCache ( ) { if ( $ this -> cacheService == null ) { return $ this -> getRoutesWithoutCache ( ) ; } else { $ routes = $ this -> cacheService -> get ( 'splashWordpressRoutes' ) ; if ( $ routes == null ) { $ routes = $ this -> getRoutesWithoutCache ( ) ; $ this -> cacheService -> set ( 'splashWordpressRoutes' , $ routes ) ; } return $ routes ; } } | Returns the list of routes as an array of arrays . Uses the cache mechanism if available . |
235 | public function getRoutesWithoutCache ( ) { $ urlsList = array ( ) ; foreach ( $ this -> routeProviders as $ routeProvider ) { $ tmpUrlList = $ routeProvider -> getUrlsList ( null ) ; $ urlsList = array_merge ( $ urlsList , $ tmpUrlList ) ; } $ items = array ( ) ; foreach ( $ urlsList as $ urlCallback ) { $ url = $ urlCallback -> url ; $ url = rtrim ( $ url , '/' ) ; $ title = null ; if ( $ urlCallback -> title !== null ) { $ title = $ urlCallback -> title ; } $ trimmedUrl = trim ( $ url , '/' ) ; $ urlParts = explode ( '/' , $ trimmedUrl ) ; $ urlPartsNew = array ( ) ; $ parametersList = array ( ) ; $ nbParam = 0 ; for ( $ i = 0 ; $ i < count ( $ urlParts ) ; ++ $ i ) { $ urlPart = $ urlParts [ $ i ] ; if ( strpos ( $ urlPart , '{' ) === 0 && strpos ( $ urlPart , '}' ) === strlen ( $ urlPart ) - 1 ) { $ nbParam += 1 ; $ varName = substr ( $ urlPart , 1 , strlen ( $ urlPart ) - 2 ) ; $ parametersList [ $ varName ] = $ i ; $ urlPartsNew [ ] = '([^/]*?)' ; } else { $ urlPartsNew [ ] = $ urlPart ; } } $ url = '^' . implode ( '/' , $ urlPartsNew ) . '$' ; $ httpMethods = $ urlCallback -> httpMethods ; if ( empty ( $ httpMethods ) ) { $ httpMethods [ 'default' ] = 'moufpress_execute_action' ; } else { foreach ( $ httpMethods as $ httpMethod ) { $ httpMethods [ strtoupper ( $ httpMethod ) ] = 'moufpress_execute_action' ; } } foreach ( $ httpMethods as $ httpMethod ) { $ item = array ( 'path' => $ url , 'page_callback' => $ httpMethods , 'page_arguments' => array ( $ urlCallback -> controllerInstanceName , $ urlCallback -> methodName , $ parametersList , $ urlCallback -> parameters , $ urlCallback -> filters ) , 'access_callback' => true , 'nbParam' => $ nbParam , ) ; if ( $ title ) { $ item [ 'title' ] = $ title ; } $ items [ ] = $ item ; } } usort ( $ items , function ( array $ a , array $ b ) { return $ a [ 'nbParam' ] - $ b [ 'nbParam' ] ; } ) ; return $ items ; } | Returns the list of routes as an array of arrays . Bypasses the cache mechanism . |
236 | public function connect ( ) : DriverInterface { $ options = $ this -> getConfig ( ) -> get ( ) ; $ optionsDriver = $ options [ 'driver_options' ] -> get ( ) ; try { $ connection = new MongoManager ( $ this -> getDsn ( ) , $ this -> getOptions ( $ options , self :: AVAILABLE_OPTIONS ) , $ this -> getOptions ( $ optionsDriver , self :: AVAILABLE_DRIVER_OPTIONS ) ) ; $ this -> setInstance ( $ connection ) ; } catch ( RuntimeException $ e ) { new Exception ( 'Unable to connect' ) ; } catch ( InvalidArgumentException $ e ) { new Exception ( 'Invalid argument provided' ) ; } return $ this ; } | Initiate connection with database |
237 | private function getOptions ( array $ options , array $ allowed ) : array { $ result = [ ] ; foreach ( $ options as $ key => $ value ) { if ( \ in_array ( $ key , $ allowed , false ) ) { $ result [ $ key ] = $ value ; } } return $ result ; } | Generate options array |
238 | private function getQuery ( array $ where , array $ options ) : MongoQuery { try { $ query = new MongoQuery ( $ where , $ options ) ; } catch ( InvalidArgumentException $ e ) { new Exception ( 'WriteConcern could not to be initiated' ) ; } return $ query ; } | Create query object from filter and option arrays |
239 | public function update ( array $ data , array $ filter = [ ] , array $ updateOptions = [ ] ) { $ bulk = $ this -> getBulk ( ) ; $ bulk -> update ( $ filter , $ data , $ updateOptions ) ; try { $ response = $ this -> getInstance ( ) -> executeBulkWrite ( $ this -> getParam ( 'database' ) . '.' . $ this -> getCollection ( ) , $ bulk , $ this -> getWrite ( ) ) ; } catch ( BulkWriteException $ e ) { new Exception ( 'Unable to write in database' ) ; } return $ response ?? false ; } | Update data in database |
240 | private function getCommand ( $ query ) : MongoCommand { try { $ command = new MongoCommand ( $ query ) ; } catch ( InvalidArgumentException $ e ) { new Exception ( 'WriteConcern could not to be initiated' ) ; } return $ command ; } | Create command from query |
241 | private function getStatus ( Theme $ theme ) { if ( $ theme -> type !== 'Backend' ) { return setting ( 'core::template' ) === $ theme -> getName ( ) ; } return config ( 'society.core.core.admin-theme' ) === $ theme -> getName ( ) ; } | Check if the theme is active based on its type . |
242 | public function findByClass ( $ className ) { $ result = [ ] ; foreach ( $ this -> _traits as $ trait ) { if ( $ trait -> matchClassName ( $ className ) ) { $ result [ ] = $ trait ; } } $ result = SortUtils :: sortReflections ( $ result ) ; return $ result ; } | Retrieve all traits by matching className |
243 | public function setFlash ( $ key , $ value ) { $ key = $ this -> explode ( $ key ) ; array_unshift ( $ key , __CLASS__ , 'flash' , 'next' ) ; $ this -> set ( $ key , $ value ) ; } | Set a flash value that will only be available on the next page request . |
244 | public function getFlash ( $ key , $ default = null ) { $ key = $ this -> explode ( $ key ) ; array_unshift ( $ key , __CLASS__ , 'flash' , 'now' ) ; return $ this -> get ( $ key , $ default ) ; } | Get a flash value that was set on the previous page request . |
245 | private function started ( ) { if ( is_null ( self :: $ started ) ) { self :: $ started = ( session_status ( ) === PHP_SESSION_ACTIVE ) ? true : session_start ( ) ; if ( self :: $ started ) { if ( ! isset ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) || strtolower ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) != 'xmlhttprequest' ) { if ( isset ( $ _SESSION [ __CLASS__ ] [ 'flash' ] [ 'next' ] ) ) { $ _SESSION [ __CLASS__ ] [ 'flash' ] [ 'now' ] = $ _SESSION [ __CLASS__ ] [ 'flash' ] [ 'next' ] ; unset ( $ _SESSION [ __CLASS__ ] [ 'flash' ] [ 'next' ] ) ; } elseif ( isset ( $ _SESSION [ __CLASS__ ] [ 'flash' ] ) ) { unset ( $ _SESSION [ __CLASS__ ] ) ; } } } } return self :: $ started ; } | Start a new or update an existing session . |
246 | public function letOnContext ( $ constraint ) { $ this -> defaultValue ( static :: FIELD_SELF , null ) ; return $ this -> let ( static :: FIELD_SELF , $ constraint ) ; } | Add a constraint that only works on the context . These are complex constraints that usually work on more than one field at a time . |
247 | public function defaultValue ( $ field , $ value ) { Arguments :: define ( Boa :: string ( ) , Boa :: any ( ) ) -> check ( $ field , $ value ) ; $ this -> defaults = $ this -> defaults -> insert ( $ field , $ value ) ; return $ this ; } | Set the default value of a field . |
248 | public function let ( $ field , $ constraint ) { Arguments :: define ( Boa :: string ( ) , Boa :: either ( Boa :: instance ( AbstractConstraint :: class ) , Boa :: arrOf ( Boa :: instance ( AbstractConstraint :: class ) ) ) ) -> check ( $ field , $ constraint ) ; if ( ! $ this -> constraints -> member ( $ field ) ) { $ this -> constraints = $ this -> constraints -> insert ( $ field , ArrayList :: zero ( ) ) ; } if ( ! is_array ( $ constraint ) ) { $ constraint = [ $ constraint ] ; } $ this -> constraints = $ this -> constraints -> insert ( $ field , Maybe :: fromMaybe ( ArrayList :: zero ( ) , $ this -> constraints -> lookup ( $ field ) ) -> append ( ArrayList :: of ( $ constraint ) ) ) ; return $ this ; } | Add one or more constraints to a field . |
249 | public function required ( $ fields ) { Arguments :: define ( Boa :: either ( Boa :: string ( ) , Boa :: arrOf ( Boa :: string ( ) ) ) ) -> check ( $ fields ) ; if ( ! is_array ( $ fields ) ) { $ fields = [ $ fields ] ; } $ this -> required = $ this -> required -> append ( ArrayList :: of ( $ fields ) ) ; return $ this ; } | Add one or more fields to the list of fields that are required . |
250 | public function make ( ) { return new Spec ( $ this -> constraints -> toArray ( ) , $ this -> defaults -> toArray ( ) , $ this -> required -> toArray ( ) ) ; } | Build an instance of the defined Spec . |
251 | protected function renderTpl ( $ tpl , $ data = array ( ) ) { if ( ! empty ( $ tpl ) ) { extract ( $ data ) ; ob_start ( ) ; eval ( '?>' . $ tpl . '<?php ' ) ; $ tpl = ob_get_clean ( ) ; } return $ tpl ; } | Renders a . tpl . php file . |
252 | public function filter ( array $ data ) { $ filteredData = [ ] ; foreach ( $ data as $ value ) { if ( $ this -> match ( $ value ) ) { $ filteredData [ ] = $ value ; } } return $ filteredData ; } | Performs filtering of given array |
253 | public function getSlug ( $ langCode ) { $ slug = false ; foreach ( $ this -> i18n as $ i18nModel ) { if ( $ i18nModel -> lang_code == $ langCode ) { $ slug = $ i18nModel -> slug ; break ; } } return $ slug ; } | Get slug of this model for selected language |
254 | public function detach ( EventManagerInterface $ events ) { $ sharedManager = $ events -> getSharedManager ( ) ; foreach ( $ this -> listeners as $ index => $ listeners ) { if ( $ listeners === $ this ) { continue ; } if ( $ listeners instanceof ListenerAggregateInterface ) { $ listeners -> detach ( $ events ) ; } $ events -> detach ( $ listeners ) ; } foreach ( $ this -> sharedListeners as $ id => $ sharedListeners ) { foreach ( $ sharedListeners as $ index => $ listener ) { if ( $ listener === $ this ) { continue ; } if ( $ listener instanceof ListenerAggregateInterface ) { $ listener -> detach ( $ events ) ; } $ sharedManager -> detach ( $ listener , $ id ) ; } } } | Detach all previously attached listeners . |
255 | protected function checkLazyLoad ( ) { if ( $ this -> lazyLoadInitiated === true ) { return ; } $ this -> lazyLoad ( ) ; $ this -> generateKeys ( ) ; $ this -> lazyLoadInitiated = true ; } | Performs lazy load checks and loads items if required . |
256 | public function callSetter ( & $ object , $ key , $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ object , $ method ) ) { $ object -> $ method ( $ value ) ; return true ; } return false ; } | Call object set method for a key and pass value |
257 | public function indexAction ( ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ visits = $ em -> getRepository ( 'CoreExtraBundle:Visit' ) -> findAll ( ) ; return array ( 'visits' => $ visits , ) ; } | Lists all visit entities . |
258 | public function newAction ( Request $ request ) { $ visit = new Visit ( ) ; $ form = $ this -> createForm ( 'CoreExtraBundle\Form\VisitType' , $ visit ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ visit ) ; $ em -> flush ( $ visit ) ; if ( $ request -> isXMLHttpRequest ( ) ) { return new JsonResponse ( array ( 'id' => $ visit -> getId ( ) , ) ) ; } $ email = $ visit -> getActor ( ) -> getEmail ( ) ; $ emailToken = new EmailToken ( ) ; $ emailToken -> setEmail ( $ email ) ; $ token = sha1 ( uniqid ( ) ) ; $ emailToken -> setToken ( $ token ) ; $ em -> persist ( $ emailToken ) ; $ visit -> setEmailToken ( $ emailToken ) ; $ em -> flush ( ) ; $ template = $ this -> get ( 'twig' ) -> loadTemplate ( 'CoreExtraBundle:Email:email.template.html.twig' ) ; $ body = $ template -> renderBlock ( 'body' , array ( 'user_name' => $ visit -> getActor ( ) -> getFullName ( ) , 'place_name' => 'Place name' ) ) ; $ body = preg_replace ( '/(#TOKEN#)/' , $ token , $ body ) ; $ this -> get ( 'core.mailer' ) -> sendFeedback ( array ( $ email ) , $ body , 'Place Name' ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'visit.sent' ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'visit.created' ) ; return $ this -> redirectToRoute ( 'visit_show' , array ( 'id' => $ visit -> getId ( ) ) ) ; } return array ( 'visit' => $ visit , 'form' => $ form -> createView ( ) , ) ; } | Creates a new visit entity . |
259 | public function showAction ( Visit $ visit ) { $ deleteForm = $ this -> createDeleteForm ( $ visit ) ; return array ( 'visit' => $ visit , 'delete_form' => $ deleteForm -> createView ( ) , ) ; } | Finds and displays a visit entity . |
260 | private function createDeleteForm ( Visit $ visit ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'visit_delete' , array ( 'id' => $ visit -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; } | Creates a form to delete a visit entity . |
261 | public function find ( $ key ) { $ template = $ this -> getCollection ( ) -> get ( $ key ) ; if ( $ template !== null ) { return $ template ; } throw new NotFoundException ( "Media template $key not found." ) ; } | Find template . |
262 | public function updateTemplate ( TemplateInterface $ template ) { $ template -> setRevision ( $ template -> getRevision ( ) + 1 ) ; $ this -> dumper -> dumpTemplate ( $ template ) ; } | Update template . |
263 | public static function register ( LoggerInterface $ logger = null , ExceptionConfig $ cfg = null ) { self :: $ registered = true ; $ class = get_called_class ( ) ; $ handler = new $ class ( $ logger , $ cfg ) ; set_exception_handler ( [ $ handler , 'handle' ] ) ; self :: $ lastRegisteredHandler = & $ handler ; return $ handler ; } | Registers the exception handler |
264 | protected function handleCLI ( $ e ) { $ this -> console -> write ( '<eb>Uncaught ' . get_class ( $ e ) . ': </>' ) -> write ( '<e>[' . $ e -> getCode ( ) . '] ' . $ e -> getMessage ( ) . '</>' , true ) -> write ( '<e>Raised in </>' ) -> write ( '<eu>' . $ e -> getFile ( ) . '</>' ) -> write ( '<e> @ line </>' ) -> write ( '<eu>' . $ e -> getLine ( ) . '</>' , true ) ; $ this -> echoPreviousExceptions ( $ e -> getPrevious ( ) ) ; $ this -> console -> write ( '<eb>Debug backtrace:</eb>' , true ) -> writeln ( '' ) ; echo $ this -> getTrace ( $ e -> getTrace ( ) , 'e' ) ; } | Handles the exception with CLI output |
265 | protected function echoPreviousExceptions ( $ e , $ level = 0 ) { if ( $ level < $ this -> config -> prevExceptionDepth && $ e ) { if ( $ this -> isCLI ) { $ this -> console -> write ( '<eb>Preceded by </>' ) -> write ( '<e>[' . $ e -> getCode ( ) . '] ' . $ e -> getMessage ( ) . '</>' ) -> write ( '<e> @ ' . $ e -> getFile ( ) . '\'s line ' . $ e -> getLine ( ) . '</>' , true ) -> writeln ( '' ) ; } else { ?> <div> <span class="alo-bold">Preceded by </span> <span>[ <?= $ e -> getCode ( ) ?> ]: <?= $ e -> getMessage ( ) ?> </span> <span> @ </span> <span class="alo-uline"> <?= $ e -> getFile ( ) ?> </span> <span> @ line </span> <span class="alo-uline"> <?= $ e -> getLine ( ) ?> </div> <?php } $ this -> echoPreviousExceptions ( $ e -> getPrevious ( ) , ++ $ level ) ; } } | Echoes previous exceptions if applicable |
266 | protected function handleHTML ( $ e ) { ?> <div class="text-center"> <div class="alo-err alert alert-danger"> <div> <span class="alo-bold">Uncaught <?= get_class ( $ e ) ?> : </span> <span>[ <?= $ e -> getCode ( ) ?> ] <?= $ e -> getMessage ( ) ?> </span> </div> <div> <span class="alo-bold">Raised in </span> <span class="alo-uline"> <?= $ e -> getFile ( ) ?> <span> @ line </span> <span class="alo-uline"> <?= $ e -> getLine ( ) ?> </div> <?php $ this -> echoPreviousExceptions ( $ e -> getPrevious ( ) ) ?> <div> <span class="alo-bold">Backtrace:</span> <?= $ this -> getTrace ( $ e -> getTrace ( ) , 'e' ) ?> </div> </div> </div> <?php } | Handles an exception with HTML output |
267 | protected function log ( $ e , $ includeLocation = true ) { $ msg = '[' . $ e -> getCode ( ) . '] ' . $ e -> getMessage ( ) ; if ( $ this -> config -> logExceptionLocation && $ includeLocation ) { $ msg .= ' (occurred in ' . $ e -> getFile ( ) . ' @ line ' . $ e -> getLine ( ) . ')' ; } $ this -> logger -> error ( $ msg ) ; } | Logs a message if the logger is enabled |
268 | public function handle ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ session = $ request -> getSession ( ) ; if ( null === $ session || null === $ token = $ this -> securityContext -> getToken ( ) ) { return ; } if ( ! $ this -> hasSessionExpired ( $ session ) ) { return ; } if ( null !== $ this -> logger ) { $ this -> logger -> info ( sprintf ( "Expired session detected for user named '%s'" , $ token -> getUsername ( ) ) ) ; } $ this -> removeSessionData ( $ session ) ; if ( null === $ this -> targetUrl ) { throw new SessionExpiredException ( ) ; } $ response = $ this -> httpUtils -> createRedirectResponse ( $ request , $ this -> targetUrl ) ; $ event -> setResponse ( $ response ) ; } | Handles expired sessions . |
269 | public function fetchAll ( $ sort = null ) { $ select = $ this -> getFullTree ( ) ; $ select = $ this -> setSortOrder ( $ select , $ sort ) ; return $ this -> fetchResult ( $ select ) ; } | Gets all items in tree . |
270 | public function getFullTree ( ) { $ select = $ this -> getSql ( ) -> select ( ) ; $ select -> from ( [ 'child' => $ this -> getTable ( ) ] ) -> columns ( [ Select :: SQL_STAR , 'depth' => new Expression ( '(COUNT(parent.' . $ this -> getPrimaryKey ( ) . ') - 1)' ) ] ) -> join ( [ 'parent' => $ this -> getTable ( ) ] , 'child.' . self :: COLUMN_LEFT . ' BETWEEN parent.' . self :: COLUMN_LEFT . ' AND parent.' . self :: COLUMN_RIGHT , [ ] , Select :: JOIN_INNER ) -> group ( 'child.' . $ this -> getPrimaryKey ( ) ) -> order ( 'child.' . self :: COLUMN_LEFT ) ; return $ select ; } | Gets the full tree from database |
271 | public function getPathwayByChildId ( $ id ) { $ select = $ this -> getSql ( ) -> select ( ) ; $ select -> from ( [ 'child' => $ this -> getTable ( ) ] ) -> columns ( [ ] ) -> join ( [ 'parent' => $ this -> getTable ( ) ] , 'child.' . self :: COLUMN_LEFT . ' BETWEEN parent.' . self :: COLUMN_LEFT . ' AND parent.' . self :: COLUMN_RIGHT , [ Select :: SQL_STAR ] , Select :: JOIN_INNER ) -> where ( [ 'child.' . $ this -> getPrimaryKey ( ) . ' = ?' => $ id ] ) -> order ( 'parent.' . self :: COLUMN_LEFT ) ; return $ select ; } | Get the pathway of of the child by its id . |
272 | protected function updateTree ( $ lft_rgt , $ operator , $ offset ) { $ lft = new Where ; $ rgt = new Where ; $ lftUpdate = $ this -> update ( [ self :: COLUMN_LEFT => new Expression ( self :: COLUMN_LEFT . $ operator . $ offset ) ] , $ lft -> greaterThan ( self :: COLUMN_LEFT , $ lft_rgt ) ) ; $ rgtUpdate = $ this -> update ( [ self :: COLUMN_RIGHT => new Expression ( self :: COLUMN_RIGHT . $ operator . $ offset ) ] , $ rgt -> greaterThan ( self :: COLUMN_RIGHT , $ lft_rgt ) ) ; return [ $ lftUpdate , $ rgtUpdate ] ; } | Updates left and right values of tree |
273 | protected function getPosition ( $ id ) { $ cols = [ self :: COLUMN_LEFT , self :: COLUMN_RIGHT , 'width' => new Expression ( self :: COLUMN_RIGHT . ' - ' . self :: COLUMN_LEFT . ' + 1' ) , ] ; $ select = $ this -> getSelect ( ) ; $ where = new Where ; $ where -> equalTo ( $ this -> getPrimaryKey ( ) , $ id ) ; $ select -> columns ( $ cols ) -> where ( $ where ) ; $ row = $ this -> fetchResult ( $ select ) -> current ( ) ; return $ row ; } | Get the position of a child in the tree |
274 | public function insertRow ( array $ data , $ position = 0 , $ insertType = self :: INSERT_NODE ) { $ num = $ this -> fetchAll ( ) -> count ( ) ; if ( $ num && $ position ) { $ row = $ this -> getPosition ( $ position ) ; $ lft_rgt = ( $ insertType === self :: INSERT_NODE ) ? $ row -> getRgt ( ) : $ row -> getLft ( ) ; } else { $ lft_rgt = 0 ; } $ this -> updateTree ( $ lft_rgt , '+' , 2 ) ; $ data [ self :: COLUMN_LEFT ] = $ lft_rgt + 1 ; $ data [ self :: COLUMN_RIGHT ] = $ lft_rgt + 2 ; $ insertId = parent :: insert ( $ data ) ; return $ insertId ; } | Insert a row into tree |
275 | public function delete ( $ where , $ table = null ) { if ( is_array ( $ where ) ) { $ pk = $ where [ $ this -> getPrimaryKey ( ) ] ; } else { $ pk = ( int ) $ where ; } $ row = $ this -> getPosition ( $ pk ) ; $ where = new Where ; $ where -> between ( self :: COLUMN_LEFT , $ row -> getLft ( ) , $ row -> getRgt ( ) ) ; $ result = parent :: delete ( $ where , $ table ) ; if ( $ result ) { $ this -> updateTree ( $ row -> getRgt ( ) , '-' , $ row -> width ( ) ) ; } return $ result ; } | Deletes a row from tree . |
276 | public function addTwigPath ( string $ namespace , string $ path ) : ExtensionInterface { if ( $ this -> driver ) { throw new \ RuntimeException ( 'Driver has already been created. Namespaces cannot be added.' ) ; } $ this -> twigNamespaces [ $ namespace ] [ ] = $ path ; return $ this ; } | Add a directory to the Twig loader . |
277 | private function getPhantomProcess ( $ viewPath ) { $ system = $ this -> getSystem ( ) ; $ phantom = __DIR__ . '/bin/' . $ system . '/phantomjs' . $ this -> getExtension ( $ system ) ; return new Process ( $ phantom . ' invoice.js ' . $ viewPath , __DIR__ ) ; } | Get the PhantomJS process instance . |
278 | private function getSystem ( ) { $ uname = strtolower ( php_uname ( ) ) ; if ( str_contains ( $ uname , 'darwin' ) ) { return 'macosx' ; } elseif ( str_contains ( $ uname , 'win' ) ) { return 'windows' ; } elseif ( str_contains ( $ uname , 'linux' ) ) { return PHP_INT_SIZE === 4 ? 'linux-i686' : 'linux-x86_64' ; } else { throw new RuntimeException ( 'Unknown operating system.' ) ; } } | Get the operating system for the current platform . |
279 | private function writeViewForImaging ( InvoiceInterface $ invoice , $ storagePath ) { $ html = $ this -> htmlGenerator -> generate ( $ invoice ) ; $ storagePath = $ storagePath ? : storage_path ( ) . '/framework' ; $ this -> files -> put ( $ path = $ storagePath . '/' . $ invoice -> getId ( ) . '.pdf' , $ html ) ; return $ path ; } | Write the view HTML so PhantomJS can access it . |
280 | public function generate ( InvoiceInterface $ invoice , $ storagePath = '/tmp' ) { $ viewPath = $ this -> writeViewForImaging ( $ invoice , $ storagePath ) ; $ this -> getPhantomProcess ( $ viewPath ) -> setTimeout ( 10 ) -> run ( ) ; return $ this -> files -> get ( $ viewPath ) ; } | Get the rendered PDF of the invoice . |
281 | public function addRoute ( Route $ route ) { if ( ! in_array ( $ route , $ this -> routes ) ) { $ this -> routes [ ] = $ route ; } } | Add a route to the array of routes if not already in the array . |
282 | private function FindRouteMatch ( ) { $ route = new Route ( ) ; $ route -> setDefaultUrl ( Config :: Init ( $ this -> app ) -> Get ( \ Puzzlout \ Framework \ Enums \ AppSettingKeys :: DefaultUrl ) ) ; $ this -> getRoute ( $ route , $ this -> url ) ; return $ route ; } | Instanciate the Route object from the current request . |
283 | public function setPath ( string $ path = '' ) : void { $ this -> path = '/' ; if ( $ path != '' ) { $ this -> path .= \ substr ( $ path , 0 , 1 ) === '/' ? \ substr ( $ path , 1 ) : $ path ; } } | Sets new cookie path |
284 | public function setDomain ( string $ domain = '' , bool $ forSubdomains = true ) : void { $ subdomainIndicator = $ forSubdomains === true ? '.' : '' ; $ this -> domain = \ sprintf ( '%s%s' , $ subdomainIndicator , \ preg_replace ( '/^(\.)?(preview\.)?/' , '' , $ domain ) ) ; } | Sets new cookie domain and whether cookie should be available for subdomains or not . |
285 | public function add ( $ command , $ path , array $ arguments = array ( ) , array $ options = array ( ) ) { $ dependsOn = ( array ) Hash :: get ( $ options , 'dependsOn' ) ; $ unique = ( bool ) Hash :: get ( $ options , 'unique' ) ; unset ( $ options [ 'dependsOn' ] , $ options [ 'unique' ] ) ; $ task = compact ( 'command' , 'path' , 'arguments' ) + $ options ; $ task += array ( 'timeout' => 60 * 60 , 'status' => TaskType :: UNSTARTED , 'code' => 0 , 'stdout' => '' , 'stderr' => '' , 'details' => array ( ) , 'server_id' => 0 , 'scheduled' => null , 'hash' => $ this -> _hash ( $ command , $ path , $ arguments ) ) ; $ dependsOnIds = $ this -> find ( 'list' , array ( 'fields' => array ( 'id' , 'id' ) , 'conditions' => array ( 'hash' => $ task [ 'hash' ] , 'status' => array ( TaskType :: UNSTARTED , TaskType :: DEFFERED , TaskType :: RUNNING ) ) ) ) ; if ( $ unique && $ dependsOnIds ) { return false ; } elseif ( $ dependsOnIds ) { $ dependsOn = array_merge ( $ dependsOn , $ dependsOnIds ) ; } $ this -> create ( ) ; if ( $ dependsOn ) { $ data = array ( $ this -> alias => $ task , $ this -> DependsOnTask -> alias => $ dependsOn ) ; $ success = $ this -> saveAssociated ( $ data ) ; } else { $ success = $ this -> save ( $ task ) ; } if ( ! $ success ) { return false ; } else { return $ this -> read ( ) [ $ this -> alias ] ; } } | Adds new task |
286 | public function stop ( $ taskId , $ maxRetries = 10 ) { $ task = $ this -> read ( null , $ taskId ) ; if ( ! $ task ) { throw new NotFoundException ( "Task id=$taskId not found!" ) ; } switch ( $ task [ $ this -> alias ] [ 'status' ] ) { case TaskType :: FINISHED : case TaskType :: STOPPING : case TaskType :: STOPPED : { return true ; } case TaskType :: UNSTARTED : { return ( bool ) $ this -> saveField ( 'status' , TaskType :: STOPPED ) ; } case TaskType :: RUNNING : return ( bool ) $ this -> saveField ( 'status' , TaskType :: STOPPING ) ; case TaskType :: DEFFERED : { if ( $ maxRetries <= 0 ) { return ( bool ) $ this -> saveField ( 'status' , TaskType :: STOPPED ) ; } sleep ( 1 ) ; return $ this -> stop ( $ taskId , -- $ maxRetries ) ; } default : return false ; } } | Stop task by id |
287 | public function restart ( $ taskId ) { if ( ! $ this -> stop ( $ taskId ) ) { return false ; } $ task = array ( 'id' => null , 'stderr' => '' , 'stdout' => '' , 'status' => TaskType :: UNSTARTED , 'code' => '' , 'code_string' => '' , 'started' => '' , 'stopped' => '' , 'server_id' => 0 , ) + $ this -> read ( null , $ taskId ) [ $ this -> alias ] ; $ this -> create ( ) ; $ success = ( bool ) $ this -> saveAssociated ( array ( $ this -> alias => $ task , $ this -> DependsOnTask -> alias => array ( $ taskId ) ) ) ; return $ success ? $ this -> id : $ success ; } | Restart task by id |
288 | public function remove ( $ taskId , $ maxRetries = 10 ) { if ( ! $ this -> stop ( $ taskId , $ maxRetries ) ) { return false ; } return ( bool ) $ this -> delete ( $ taskId ) ; } | Delete task by id |
289 | protected function toggleButton ( ) { $ options = array ( 'model' => $ this -> model , 'attribute' => $ this -> attribute ) ; if ( isset ( $ this -> htmlOptions [ 'options' ] ) ) { $ options = CMap :: mergeArray ( $ options , $ this -> htmlOptions [ 'options' ] ) ; unset ( $ this -> htmlOptions [ 'options' ] ) ; } $ options [ 'htmlOptions' ] = $ this -> htmlOptions ; echo $ this -> getLabel ( ) ; echo '<div class="controls">' ; $ this -> widget ( 'bootstrap.widgets.CiiToggleButton' , $ options ) ; echo $ this -> getError ( ) . $ this -> getHint ( ) ; echo '</div>' ; } | Renders a toogle button |
290 | protected function markdownEditorJs ( ) { if ( isset ( $ this -> htmlOptions [ 'width' ] ) ) { $ width = $ this -> htmlOptions [ 'width' ] ; unset ( $ this -> htmlOptions [ 'width' ] ) ; } if ( isset ( $ this -> htmlOptions [ 'height' ] ) ) { $ height = $ this -> htmlOptions [ 'height' ] ; unset ( $ this -> htmlOptions [ 'height' ] ) ; } echo $ this -> getLabel ( ) ; echo '<div class="controls">' ; echo '<div class="wmd-panel">' ; echo '<div id="wmd-button-bar" class="btn-toolbar"></div>' ; $ this -> widget ( 'bootstrap.widgets.CiiMarkdownEditorJs' , array ( 'model' => $ this -> model , 'attribute' => $ this -> attribute , 'width' => isset ( $ width ) ? $ width : '100%' , 'height' => isset ( $ height ) ? $ height : '400px' , 'htmlOptions' => $ this -> htmlOptions ) ) ; echo $ this -> getError ( ) . $ this -> getHint ( ) ; echo '<div id="wmd-preview" class="wmd-panel wmd-preview" style="width:' . ( isset ( $ width ) ? $ width : '100%' ) . '"></div>' ; echo '</div>' ; echo '</div>' ; } | Renders a Markdown Editor . |
291 | protected static function _tagPattern ( $ open = true , $ selfClose = false ) { if ( true === $ open ) { return static :: _openStartDelimiter ( $ selfClose ) . self :: ValuePlaceholder . static :: _openEndDelimiter ( $ selfClose ) ; } return static :: _closeStartDelimiter ( ) . self :: ValuePlaceholder . static :: _closeEndDelimiter ( ) ; } | Cleans and trims a tag |
292 | protected function prepareLocal ( ) { if ( $ this -> isSmooth ( ) ) return ; $ size = filesize ( $ this -> path ) ; $ this -> setSize ( $ size ) ; if ( ! $ this -> hasDeflation ( ) ) $ this -> setDeflatedSize ( $ size ) ; $ this -> setRawCrc ( hash_file ( 'crc32b' , $ this -> path , TRUE ) ) ; } | Prepare the data required for the file header . size deflatedSize crc32 ... |
293 | public function make ( array $ attributes = [ ] ) { if ( $ this -> type === null ) { throw new InvalidArgumentException ( "You have to set the type of file!" ) ; } if ( $ this -> amount === null ) { return $ this -> makeInstance ( $ attributes ) ; } if ( $ this -> amount < 1 ) { return collect ( ) ; } return $ this -> makeCollection ( $ attributes ) ; } | Make a file or files |
294 | protected function makeInstance ( array $ attributes ) { if ( in_array ( $ this -> type , [ 'jpg' , 'png' ] ) ) { $ properties = array_only ( $ attributes , [ 'height' , 'width' , 'text' , 'background' , 'color' ] ) ; $ properties [ 'type' ] = $ this -> type ; $ attributes = array_diff ( $ attributes , $ properties ) ; $ path = ( new Image ) -> make ( $ properties ) ; } else { $ path = $ this -> faker -> file ( $ this -> filePath ( ) ) ; } return $ this -> file ( $ attributes , $ path ) ; } | Make instance from file or generated file . |
295 | protected function file ( array $ attributes , $ path ) { $ filesystem = new Filesystem ; $ file = new UploadedFile ( $ path , last ( explode ( '/' , $ path ) ) , $ filesystem -> mimeType ( $ path ) , $ filesystem -> size ( $ path ) , null , true ) ; if ( count ( $ attributes ) ) { return collect ( array_merge ( compact ( 'file' ) , $ attributes ) ) ; } return $ file ; } | Make uploaded file instance |
296 | private function loadFromExtensions ( $ content ) { foreach ( $ content as $ namespace => $ values ) { if ( in_array ( $ namespace , [ 'imports' , 'parameters' ] ) ) { continue ; } if ( ! is_array ( $ values ) ) { $ values = [ ] ; } $ this -> configCollection -> add ( $ namespace , $ values ) ; } } | Loads from Extensions |
297 | protected function getCoordParams ( array $ elementRef = null , $ x = 0 , $ y = 0 ) { return ( array ) $ elementRef + [ 'x' => ( int ) $ x , 'y' => ( int ) $ y , ] ; } | Build coordinate parameters for action . |
298 | protected function assertIsDown ( $ isDown = true ) { if ( $ this -> isDown != $ isDown ) { $ downText = $ isDown ? "up" : "down" ; throw new WebDriver_Exception ( "Touch pointer should be {$downText} for this action" ) ; } return $ this ; } | Throws exception if pointer down state is wrong . |
299 | protected function switchIsDown ( $ isDown = true ) { $ this -> assertIsDown ( ! $ isDown ) ; $ this -> isDown = ( bool ) $ isDown ; return $ this ; } | Switches to given pointer down state throwing exception if current state is wrong . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.